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

Better way to check a range of numbers? [closed]

Asked by 6 years ago

This question already has an answer here:

I dont get what the <= and >= means?

I wasn't completely sure how to word this title but pretty much I have a random number generating then I check what it came up as. Pretty much I'm wondering if theres a way to check if it is a number between say 1-5 rather than typing it all out. Hers part of the script to better show what I mean.

    local sp = rng:NextNumber(1, 6)
    wait(5)
    if sp == 1 or 2 or 3 or 4 or 5 then

Is there a way to check that range rather than typing one through five?

Marked as Duplicate by TheeDeathCaster, Programical, Vulkarin, and cabbler

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

1 answer

Log in to vote
0
Answered by
noposts 75
6 years ago

use relational operators.

if sp >= 1 and sp <= 5 then 
    -- your stuff here
end

the code checks if the random number is more than or equal to 1 and less than or equal to 5. good way to check a range of numbers.

0
`if num > 0 and num < 6 then` :P TheeDeathCaster 2368 — 6y
0
As a style aside, I find `1 <= sp and sp <= 5` much easier to read BlueTaslem 18071 — 6y
Ad