Page 1 of 1

why is this if statement evaluating false

Posted: Thu Dec 12, 2013 5:05 am
by mattmaier
I can't find any way to actually lock an image so that it acts like a background (user can't do anything to it). So, if anyone has any suggestions on that, this workaround might not be necessary.

I've got a card with a "background" image and a bunch of ovals. The idea is to drag the ovals around until the world is a better place.

In the card's script I put...

Code: Select all

on mouseDown
   if  the target is image "sketch_geniepuzzle.bmp" then
      exit mouseDown
   else
      grab the target
   end if
end mouseDown
...because I don't want to put identical "grab me's" into all of the ovals and escaping the mouseDown was the only suggestion I found to stop the "background" image from ALSO being drag-able.

It occurred to me that the problem might not be with the if-then statement. The dictionary says once something is grabbed it stays grabbed until the mouse button is released, so maybe exiting mouseDown isn't actually going to do anything anyway.

Re: why is this if statement evaluating false

Posted: Thu Dec 12, 2013 5:21 am
by dunbarx
Hi.

What happens when you set the lock in the image inspector? The image should not respond to any mouse actions, though the arrow keys will move it if in editing mode. Your idea of putting the mouseDown handler in the card script is just fine. Is the problem that the mouse can still move the image?

The if-then is fine, though it could be shortened a bit:

if the short name of the target is not... then grab the target

Craig Newman

Re: why is this if statement evaluating false

Posted: Thu Dec 12, 2013 1:00 pm
by Klaus
Hi Matt,

the problem is that THE TARGET is THE STRING -> image "name of image" and not what you might think! :D
And in that case you would need to pass it as a string like:
...
if the target = ("image" && QUOTE & "sketch_geniepuzzle.bmp" & QUOTE)
## or some other ugly non-intuitive scripting!
...

Therefore, as craig said, use the short name of the target!


Best

Klaus

Re: why is this if statement evaluating false

Posted: Fri Dec 13, 2013 3:08 am
by mattmaier
dunbarx wrote: What happens when you set the lock in the image inspector? The image should not respond to any mouse actions, though the arrow keys will move it if in editing mode.
In the image's properties, under "size & position", checking "lock size and position" does not have any effect on the "grab" command. The entry in the library just says how to use it; doesn't say how to escape it other than the user releasing the mouse button. But, as you suggested here...
dunbarx wrote: if the short name of the target is not... then grab the target
...and Klaus confirmed, the problem was with how I built the conditional (also, thanks for that approach to shortening the if-then statement). This worked. I can now grab the ovals but the background image doesn't move.

Code: Select all

on mouseDown
   if  the short name of the target is not "sketch_geniepuzzle.bmp" then grab the target
end mouseDown
Klaus, thanks for explaining what I was doing wrong re: using "the target" vs "the short name of the target."

Is there a way to make that conditional less brittle? That image has ID 1015. If I need to change it in the future, and it has a different filename, when I import it can I tell LiveCode to just swap the new file into the same image ID and use the image ID in the conditional?