How can I set a lower and upper bound value for a variable in a if-statement in lua programming language? I need something like the pseudocode below.
if ("100000" >= my_variable <= "80000") then
do stuff...
end
I’ve tried different formats but my application keeps crashing.
Update:
To anyone with the same sort of doubts about lua’s syntax, i’d recommend checking the documentation here and keeping it handy. It’ll be useful while learning.
You should convert your string to a number, if you know for sure that it should be a number, and if there is no reason for it to be a string.
Here’s how to do a comparison for a range:
Notice the
and. Most programming languages don’t expand the formx < y < ztox < y AND y < zautomatically, so you must use the logicalandexplicitly. This is because one side is evaluated before the other side, so in left-to-right order it ends up going fromx < y < ztotrue < zwhich is an error, whereas in the explicit method, it goes fromx < y AND y < ztotrue AND y < ztotrue AND true, totrue.