instead of doing “if X == 1 or X == 2 or X == 3” ect, is there a way to just do this?
“if X == 1-10 then”
Im just curious, probably wont use it…
instead of doing “if X == 1 or X == 2 or X == 3” ect, is there a way to just do this?
“if X == 1-10 then”
Im just curious, probably wont use it…
Yes, there are for var = x,y,z do loop. (These are just variables)
for i = 1, 10, 1 do
if X == i then
return X
end
end
Here the Explanation:
x = Is basically where you want to start, more likely on 1 or depending on its logic highest. Your decision.
y = The range of it, where the loop should end. If y = 10, then it would run 10 times.
z = The process, what I mean is in what range it should go. If you want to keep it at 1, you don’t need to write it down. But if you want it something else, you need to write it down. What it exactly does is like, if you for example choose 2, then instead of going 1,2,3,4 … it goes 2,4,6,8… . It is mostly used for something to display or get its value higher since “i” will get is number of position in queqe.
Detail of i:
“for … = x,y,z do”, there where … can stand anything you want. It is just a variable for its position, so like if you do 1, 10,1 and lets say it ran 5 times already, the i will be 5. You can also go in negative so like
for _ = -5, 0, 1 do
if you have any more question, feel free to ask.
You could do
if X >= 1 and X <= 10 then
end
If it needs to specifically be an integer you could do
if X >= 1 and X <= 10 and math.round(X) == X then
end
Cool! I didnt know that was a thing. im learning scripting and im trying to find the limits and/or cool things you can do with Roblox’s luau
i feel like this version is alittle bit more complicated than needed, but i havnt used any of the 2 versions suggested, so i cant say much
You must be joking? The other person’s solution is not good for other things, if you would have said only integers, you could have spared me some time. Mine is about having a loop and able to do something else with it, even if it is not an integer.
Another thing you could do is:
if math.clamp(x, 1, 10) == x then
math.clamp keeps a number in a range, then you can just check if the clamped number is the same as the old one
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.