Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is it possible to use a NumberRange in an if statement? I can't seem to get one to work?

Asked by 5 years ago

So I am trying to use a numberrange in a if statement, this is what I'm doing:

if player.leaderstats.Stage.Value == NumberRange.new(10,21) then
    print("yes")
end

When I test it there are no errors, but yes does not get printed? I can't find anything on the wiki about it? Any help would be much appreciated.

0
What you're actually doing is checking if the value is equal to many numbers. A "range" of numbers is practically a list of numbers from the minimum to the maximum. DeceptiveCaster 3761 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

It wouldn't make sense to compare a number to a huge bunch of numbers in a NumberRange because it will take forever and I doubt the compiler will approve of that. However, you can check if the number is greater than or equal to the Min of the NumberRange and less than or equal to the Max so you can know if the number is in range. lua local val = player.leaderstats.Stage.Value -- To avoid repeating "player.leaderstats.Stage.Value" local range = NumberRange.new(10,21) -- Store it in a variable because we are using this more than once. if val >= range.Min and val <= range.Max then print("yes") end

If you have any questions, feel free to leave them in the comments. I hope this will work.

0
Ah, I see.. I understand now. Thank you! Pizzafireme 14 — 5y
Ad

Answer this question