IF OR THEN

Posted by Magellan on Mon 31 Jul 2017 04:18 AM — 4 posts, 19,697 views.

#0
just trying to figure out if i have done this right or not. i am trying to have a trigger evaluate between two variables, if either are true, i want it to activate.

if (rX) <= "45" or (rY) <= "45" then


this line works if the first is true, but doesn't seem to work on the second. any suggestions? (also sorry if this is on the forum somewhere, i spent some time searching and couldn't find a relevant answer.
Australia Forum Administrator #1
Normally you compare without the quotes.


 if rX <= 45 or rY <= 45 then


What are rX and rY? Can you post the trigger please?

Template:copying
For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.
#2
i got it to work using AND which now that i've slept makes sense. at the time it didn't. but basically i'm tracking how far from a waypoint i am so it gives me a warning when i've traveled too far from it.


rX = GetVariable ("rX")
rY = GetVariable ("rY")
if (rX) <= "50" and (rY) <= "50" then
Note ("ok")
else
Note ("Out of Range")
end

#3
It looks like you're trying to compare them as numbers. When you use GetVariable, it returns a string (i.e. it looks like text rather than a number).

It looks like you're using Lua, so:


rX = tonumber(GetVariable ("rX"))
rY = tonumber(GetVariable ("rY"))
if rX <= 50 and rY <= 50 then
Note ("ok")
else
Note ("Out of Range")
end


The tonumber() bits were added, and the quotes were removed from the numbers in the if..then part. The quotes made "50" also look like text rather than a number and you don't want to generally compare a string like that unless you're looking for equal to/not equal to.