Two qustions re: set loc and optionMenus

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
AtoZ
Posts: 64
Joined: Tue Mar 06, 2012 8:31 am

Two qustions re: set loc and optionMenus

Post by AtoZ » Fri Apr 06, 2012 4:32 am

I'm trying to a couple of what would seem to be fairly simple things in LiveCode, but I must be missing somthing essential in both cases. I've checked the LC Dictionary, the Users' Guide, the forums, and elsewhere, but can't seem to find out what I'm doing wrong.

1) In the openStack handler of my stack, I want to position the stack slightly above the center of the screen. I tried using the following code:

Code: Select all

set the loc of this stack to the screenLoc
set item 2 of the loc of this stack to (item 2 of the loc of this stack - 30)
When I compile the script I get an error message for the 2nd of the two lines:

compilation error at line 17 (Properties: token is not a property) near "item", char 10

Can someone explain to me what the error message means? And what the correct way is to script what I need?

--------------------------

2) I want the user of my stack to be able to choose whether or not to have a backdrop behind the stack. I created an optionMenu button with two options: Yes and No, and wrote the following script.

Code: Select all

on menuPick pItemName
     switch pItemName
          case pItemName = "Yes"
               set the backdrop to 100,100,100
               break
          case pItemName = "No"
               set the backdrop to none
               break
     end switch
end menuPick
It compiles without error messages, but when I select either of the options in the run mode, nothing happens. What am I missing?
Using LiveCode 5.5 on Windows 7 Home Premium Edition, Service Pack 1

Image
On my way from A TO Z, I often end up AT OZ.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Two qustions re: set loc and optionMenus

Post by sturgis » Fri Apr 06, 2012 5:00 am

Ok for the first part. The issue is that you can't set an ITEM of a property directly. To do this you need to put the value of the property into a temp variable change it as needed then set the property to the new values. YOu can skip the intermediate step with a bit of work.
So, first method
put the loc of this stack into tempvar
subtract 30 from item 2 of tempvar
set the loc of this stack to tempvar

Or you can
set the loc of this stack to (item 1 of the loc of this stack & comma & item 2 of the loc of this stack -30)
I think. Didn't try it but it should be close.

For the other part. I don't think you can mix forms on switch. YOu can either switch pwhatevervalue.... and then have case "value" or you can have an blank switch and evaluations for each case statement. In this case, to do what you want this should work.

on menuPick pItemName
switch pItemName
case "Yes"
set the backdrop to 100,100,100
break
case "No"
set the backdrop to none
break
end switch
end menuPick

As mentioned, the other method would be like so...
on menuPick
switch
case pItemName is "Yes"
set the backdrop to 100,100,100
break
case pItemName is "No"
set the backdrop to none
break
end switch
end menuPick
AtoZ wrote:I'm trying to a couple of what would seem to be fairly simple things in LiveCode, but I must be missing somthing essential in both cases. I've checked the LC Dictionary, the Users' Guide, the forums, and elsewhere, but can't seem to find out what I'm doing wrong.

1) In the openStack handler of my stack, I want to position the stack slightly above the center of the screen. I tried using the following code:

Code: Select all

set the loc of this stack to the screenLoc
set item 2 of the loc of this stack to (item 2 of the loc of this stack - 30)
When I compile the script I get an error message for the 2nd of the two lines:

compilation error at line 17 (Properties: token is not a property) near "item", char 10

Can someone explain to me what the error message means? And what the correct way is to script what I need?

--------------------------

2) I want the user of my stack to be able to choose whether or not to have a backdrop behind the stack. I created an optionMenu button with two options: Yes and No, and wrote the following script.

Code: Select all

on menuPick pItemName
     switch pItemName
          case pItemName = "Yes"
               set the backdrop to 100,100,100
               break
          case pItemName = "No"
               set the backdrop to none
               break
     end switch
end menuPick
It compiles without error messages, but when I select either of the options in the run mode, nothing happens. What am I missing?

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10320
Joined: Wed May 06, 2009 2:28 pm

Re: Two qustions re: set loc and optionMenus

Post by dunbarx » Fri Apr 06, 2012 5:05 am

Hi. Just takes a little practice.

A loc is a property, but an item of a loc is not, it is a token.

You can set a loc to a value defined as a pair of integers separated by a comma. You cannot set item 2 of a loc.
Try this:

Code: Select all

on mouseUp
   set the loc of this stack to the screenLoc
   set the loc of this stack to item 1 of the loc of this stack & "," & item 2 of the loc of this stack - 30
end mouseUp
Your other thing is more subtle. Try this:
on menuPick pItemName
     switch pItemName
          case "yes"
               set the backdrop to 100,100,100
               break
          case "no"
               set the backdrop to none
               break
     end switch
end menuPick
The difference? Syntax. The switch control structure requires that each case statement refer directly to the switched variable, which is already declared, you might say, and though it seems to read nicely, it just doesn't compute.

Your errors are normal. your effort is admirable. It gets easier with that first thing I mentioned, practice.

Craig Newman

AtoZ
Posts: 64
Joined: Tue Mar 06, 2012 8:31 am

Re: Two qustions re: set loc and optionMenus

Post by AtoZ » Fri Apr 06, 2012 7:31 am

Sturgis & Craig,

Thanks to both of you for your quick & detailed replies.

I get what you're saying. It's always the details, especially in coding.

I must say it seems passing strange to me that you can't set property items the same way as you can set items in a variable. I'm sure there's a reason for it, but for a program that touts itself as a "natural language" program, it's the kind of detail the can drive a beginner crazy. I must admit, however, that I do remember reading somewhere in the documentation about this -- it just didn't sink in at the time. I can't promise I won't try to do it again (it seems so natural to me), but at least when I get that enigmatic compile error, I should remember the fix. Smile.

As for the "switch" problem, I don't remember about being warned about not mixing the "styles", or even that they're were two styles (it could be there, I just don't remember it). Again, it seems to me that a program as flexible as LiveCode is, should be able to cope with the mixing. (I know, it's easy to say, but...there are no doubt good reasons for it.)

It's just another detail to try to keep straight (like trying to remember when to use "the" in your code).

I really don't want to sound like I'm complaining (too much). It's just me needing to vent a little over several lost hours of trying to tract down the solutions to these little buggers.

Thanks again for you help.
Using LiveCode 5.5 on Windows 7 Home Premium Edition, Service Pack 1

Image
On my way from A TO Z, I often end up AT OZ.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Two qustions re: set loc and optionMenus

Post by mwieder » Fri Apr 06, 2012 5:41 pm

As for the "switch" problem, I don't remember about being warned about not mixing the "styles", or even that they're were two styles (it could be there, I just don't remember it). Again, it seems to me that a program as flexible as LiveCode is, should be able to cope with the mixing. (I know, it's easy to say, but...there are no doubt good reasons for it.)
Well, here's the thing: if you have a construct of the form

Code: Select all

switch whatever
  case something
    doSomething
    break
end switch
the compiler will attempt to compare something with "whatever" and if they match it will execute "doSomething".

If you try something like

Code: Select all

switch whatever
  case something = 1
    doSomething
    break
end switch
then your line "something=1" will evaluate to true or false. The compiler will then try to match "whatever" with true or false. Since this will probably fail your "doSomething" routine will not get executed.

You can also use the shorthand form where there's no initial value to compare

Code: Select all

switch
  case something = 1
    doSomething
    break
end switch
But I've never liked that - to me it seems much harder to read.

So it's not that you can't mix styles, you just have to be very tricky to do it, and in most cases it's not what you want to do in the first place.

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Two qustions re: set loc and optionMenus

Post by sturgis » Fri Apr 06, 2012 8:04 pm

Ah k thx mark. The switch thing makes more sense to me now too!

AtoZ
Posts: 64
Joined: Tue Mar 06, 2012 8:31 am

Re: Two qustions re: set loc and optionMenus

Post by AtoZ » Fri Apr 06, 2012 11:17 pm

OK, thanks everyone. I have now the answers to both of the problems had:

I can now position my stack in one line, rather than the two I was trying before, by using this:

set the loc this stack to (item 1 of the screenLoc & comma & item 2 of the screenLoc - 30)

The above compiles without error messages and, more importantly, when I open the stack, it does not generate any error messages and it does what I want.

--------

Thanks to Mark, I think I now understand the concept of where I was going wrong (as opposed to just blindly just following a "rule"). That helps a lot. Thanks for taking the time to explain it.

I now have just "Yes" and "No" after each of the two case statements in my routine, and everything is working fine.

--------

Now that I have the optionMenu button working for displaying a backdrop, I've noticed a couple of things about how it interacts with the program's preference settings for displaying a backdrop:

I have LiveCode set to display a custom backdrop color (I don't like seeing my desktop screen while I work).

If I set or clear the backdrop from a script, it takes effects immediately, overriding whatever I had set in the preferences option for LiveCode. (Which is what I would expect).

But if I then go to Edit --> Preferences --> Appearance, the setting for the backdrop still shows my previous choice, not the actual, current backdrop. I would have expected the dialog window to pick up the current backdrop setting when it opens.

Furthermore, if I set the backdrop to "none" from my script, the backdrop setting in the Appearance window becomes essentially inoperative. The only way I have found to restore the backdrop is to set it from the message window.

And it also seems odd to me that there is no obvious was to set the backdrop to "none" from the Appearance window.

Finally, will the backdrop setting would continue to work if I turn my stack into a standalone?
Using LiveCode 5.5 on Windows 7 Home Premium Edition, Service Pack 1

Image
On my way from A TO Z, I often end up AT OZ.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7392
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Two qustions re: set loc and optionMenus

Post by jacque » Mon Apr 09, 2012 9:29 pm

The backdrop setting in preferences just controls the color when you choose Backdrop from LiveCode's View menu. It isn't a live global setting, and it won't apply at all in a standalone.

If you've set a custom backdrop via script, the Backdrop menu item in the View menu will be ticked, and you can choose it again to turn off the backdrop if you want. Of course, that's an IDE menu that won't be available in your standalones. You can also turn the backdrop on again from the View menu if a script has removed it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

AtoZ
Posts: 64
Joined: Tue Mar 06, 2012 8:31 am

Re: Two qustions re: set loc and optionMenus

Post by AtoZ » Tue Apr 10, 2012 3:25 am

Jacqueline,

Thanks for the response on backdrops. I was about to repost my questions regarding them since I sort of buried them at the end of another topic (my bad).

Since I can't use LC backdrops in a standalone (and for this particular stack I do want the option to show them), I think I should be able to simulate a backdrop by enlarging the card size to the size of the user's screen. (It would be good if I can turn off the title bar, but I haven't researched that possibility yet). I would also have to add (in the background) a box just slightly larger than the pre-backdrop window to define the working area. This would be good enough (even if I have to show the title bar). This stack has no menubar so I don't have to deal with that situation here. I would appreciate hearing from anyone who see any problems with this simulated backdrop approach.

Thanks again for the info.
Using LiveCode 5.5 on Windows 7 Home Premium Edition, Service Pack 1

Image
On my way from A TO Z, I often end up AT OZ.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7392
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: Two qustions re: set loc and optionMenus

Post by jacque » Tue Apr 10, 2012 4:42 pm

I wasn't very clear, I think. You can use backdrops in a standalone. I only meant that the color you select in the preferences applies only to the IDE, and that the View menu uses that color.

Your standalone scripts can set and remove a backdrop at will, you just need to script it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

AtoZ
Posts: 64
Joined: Tue Mar 06, 2012 8:31 am

Re: Two qustions re: set loc and optionMenus

Post by AtoZ » Wed Apr 11, 2012 7:53 am

Thanks for the clarification. I'm glad to learn that backdrops work in standalones. Can't wait to get my little stack/program up and running.
Using LiveCode 5.5 on Windows 7 Home Premium Edition, Service Pack 1

Image
On my way from A TO Z, I often end up AT OZ.

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Two qustions re: set loc and optionMenus

Post by Klaus » Wed Apr 11, 2012 2:51 pm

Hi AtoZ,

never forget:
The LiveCode IDE is written in LiveCode, so everything you see in the IDE can be scripted! :D


Best

Klaus

Post Reply