Reputation:
I use very simple Lua scripting in an online game called ROBLOX. My problem is that values in my scripts aren't changing! Example:
num = 0
while true do
num = num + 1
print(num)
wait(1)
end
That should count up starting on 0, but the number won't change. Could this be from the ROBLOX website? I can't figure out what else it might be.
Upvotes: 0
Views: 702
Reputation: 3113
Try this:
local num = 0
while true do
num = num + 1
print(num)
print(type(num))
wait(1)
end
Upvotes: 0
Reputation: 4305
There is no error in your code. If you are using ROBLOX, then I'm not sure how you're running it wrong as it is a fairly simple interface. I'll try it in ROBLOX and see if it errors for me.
To the people who were wondering about wait(): it's a ROBLOX-specific global function, that pauses the current task the amount of seconds in the parentheses.
Upvotes: 0
Reputation: 1211
There is nothing wrong with the code. You must be running it wrong. Also, wait is a function defined in the Roblox API. It is legit.
Upvotes: 0
Reputation: 15494
I just put your code in the Lua demo and it works fine if you remove the wait() function call. I'm assuming you defined this function somewhere?
Upvotes: 0
Reputation: 41220
What happens with
local num = 0
while true do
num = num + 1
print(num)
wait(1)
end
?
Maybe some other part of the system is changing the global num
.
Upvotes: 6