How do you use a range of numbers in an if statement in livecode?

480 views Asked by At

How do you do a range of numbers in livecode? I tried using "-" like this

if the loc of the image "yellowdisck.png" is 0 50,0-640 then

But this doesn't work.

3

There are 3 answers

2
Devin On BEST ANSWER

It looks like you're trying to determine whether an object's location (its center point) falls within a rectangular area. Try using the is within operator:

if the loc of image "yellowdisk.png" is within the rect of graphic "targetRect" then
   # do true stuff
else
   # do false stuff
end if
0
dunbarx On

Do you want to find out if the loc of an image is within certain bounds? You would do this:

put item 1 of the loc of ing "yourImage" into x
put item 2 of the loc of ing "yourImage" into y
if x > 100 and x < 200 and y > 100 and y < 200 then...

That sort of thing.

Craig Newman

0
Scott Rossi On

If you use a loc (location), you need to check the horizontal and vertical values separately. Assuming your horizontal range is 0 to 50 and the vertical range is 0 to 640 (inclusive):

put the loc of img "yellowdisk.png" into theLoc
put item 1 of theLoc into x
put item 2 of theLoc into y
if x>=0 and x<=50 and y>=0 and y<=640 then
   -- true: do my stuff here
else
   -- false: do something else
end if