Condensing/recognized script shorthand for "set" c

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Condensing/recognized script shorthand for "set" c

Post by gyroscope » Wed Dec 31, 2008 2:40 pm

(edit: title should be: ......for "set" code)

I've often wondered this, practically ever since I started using Rev (about 9 months ago):

If only a script similar to this

Code: Select all

set the visible of image "BLUE BACK" to false
    set the visible of image "Wiper" to false
    set the visible of button "Add" to false
    set the visible of button "CheckB" to false
could be:

Code: Select all

set the visible of image "BLUE BACK" and image "Wiper" and button "Add" and button "CheckB" to false
This causes an error although I wonder if there is a similar condensed version which does work? For readability, had this worked, it could have been:

Code: Select all

set the visible of\ 
image "BLUE BACK" and\
image "Wiper" and\
button "Add" and\
button "CheckB"\ 
to false
Also, if only

Code: Select all

set the visible of image "BLUE BACK" to false
    set the enabled of image "BLUE BACK" to false
    set the highlight of image "BLUE BACK" to false
could be:

Code: Select all

set the visible and the enabled and the highlight of image "BLUE BACK" to false
or better still:

Code: Select all

set the (visible and enabled and highlight) of image "BLUE BACK" to false
Would anyone else find this useful/easier? (It'd certainly be quicker...)
And is there already proper shorthand versions of the above, can anyone tell me please :?:

hamlynart
Posts: 101
Joined: Wed Mar 19, 2008 7:10 pm
Contact:

Post by hamlynart » Sun Jan 04, 2009 7:26 pm

Couldn't agree with you more - I've often wondered the same myself.

Yesterday I also wished there was an alternative this:

Code: Select all

If the fld "betweenStates" >= 5 and the fld "betweenStates" <= 10
could be this:

Code: Select all

If the fld "betweenStates" is >=5 and <= 10
or better still:

Code: Select all

If the fld "betweenStates" is between 5 and 10
and while I'm on the subject what about:

Code: Select all

If fld "extremities" is <= 5 or >= 10
instead of:

Code: Select all

if fld "extremities" <= 5 or fld "extremities" >=10
We can but hope!

Jim H

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Sun Jan 04, 2009 8:25 pm

gyroscope,

Code: Select all

put "img 'Some Image 1'" & cr & "img 'Some Image 2'" & cr & \
"btn 'Some Button 1'" & cr & "btn 'Some Button 2'" into myList
replace "'" with quote in myList
repeat for each line myObject in myList
  set the visible of myObject to true
end repeat
This is only one of very many way to shorten your code. Another way might be, in some cases:

Code: Select all

set the visible of grp "Some fields and some buttons" to true
or even shorter:

Code: Select all

show grp "Some fields and some buttons"
Be creative and you'll find a solution.


Hamlynart,

Code: Select all

put fld "Some Value" into V
if V >= 5 and V <= 10 and V >= 15 and V <=20 then
  -- do someting here
end if
I very rarely do this, because I prefer to use meaningful variable names, but if you have a really very long if statement, you might add a comment to document the meaning of V and use V (or any other letter except A) instead of the field reference.

I don't use A, because A is a keyword. That's merely a matter of taste and style, though.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Mon Jan 05, 2009 12:35 am

Thank you Mark, for your neat solutions. The only thing I would say about showing a group is that perhaps I might want to hide an individual one sometimes, so that I'd have to ungroup, then regroup again without the individual one, etc...if you get what I mean.

Still, useful to know.
Be creative and you'll find a solution.
I do try! :wink:

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4172
Joined: Sun Jan 07, 2007 9:12 pm

Post by bn » Mon Jan 05, 2009 12:46 pm

hi gyroscope,
I suppose you want the shortcut for repeatedly turning on and off a number of controls. You might consider putting this into a command like

Code: Select all

on showHide ptrue
    set the visible of field 1 to ptrue
    set the visible of btn 1 to ptrue
    set the visible of field 2 to not ptrue
    set the visible of button 2 to not ptrue
    -- and so on
end showHide
and call this depending on your needs like this

Code: Select all

on mouseUp pMouseBtnNo
    -- some code here
    -- condition here
    showHide true
    --else
    showHide false
    -- end condition
    -- rest of code
end mouseUp
If you put the command showHide into the card script or the stack script you can call it from different places. It saves a lot of scripting especially if you want to add controls to be shown / hidden later on. I use this stuff for example in a tabbed control on a substack with just one card and 3 tabs. Just turning on and off fields etc wholesale depending on the tab.
As Mark said, there many ways to do this.
cheers
bernd

Mark Smith
Posts: 179
Joined: Sat Apr 08, 2006 11:08 pm
Contact:

Post by Mark Smith » Mon Jan 05, 2009 1:19 pm

Code: Select all

If the fld "betweenStates" >= 5 and the fld "betweenStates" <= 10
What I tend to do in these cases is

Code: Select all

get fld "betweenStates"
if it >=5 and it <= 10 then....
I find this use of the 'it' variable helps me to keep things readable and clear.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Mon Jan 05, 2009 1:39 pm

Hi Mark,

I avoid using the it variable as much as possible, because it can easily cause unexpected errors. Too often, I wrote scripts that used the it variable, entered a small piece of code that included an answer or it command, and discovered I had to adjust my entire script.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

gyroscope
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 404
Joined: Tue Jan 08, 2008 3:44 pm
Contact:

Post by gyroscope » Tue Jan 06, 2009 12:43 am

Jim:
We can but hope!
Hope springs eternal, as they say!

That's a neat way to show and hide stuff Bernd, thank you.

:)

Post Reply