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

How can you make a delay?

Asked by
Exsius 162
9 years ago

Decided to rewrite this hopefully to make it more simple and understandable.

How can you make a second variable record the first variables values.

for example:

*Variable 1 starts setting to random numbers (ex/ 1,5,3,7,3)

variable 2 waits 1 second and then starts from the beginning of Variable 1 (ex/ 1,5,3,7,3)*

I don't want to set Variable 2 to the newest value of number of Variable 1

Sorry for confusion.

0
Why would you use var 1 + 1 if it's already a for loop? It looks to me you're asking the wrong question, and you just need help on general aspects of coding. aquathorn321 858 — 9y
0
I rewrote it to make a little more sense, hopefully you will under stand now. Sorry :) Exsius 162 — 9y

3 answers

Log in to vote
0
Answered by 9 years ago

If you want var2 to be whatever var1 was 1 second ago, use this:

function SetVar1(value)
    var1 = value
    delay(1, function() var2 = value end)
end
SetVar1(5)

With this method, you never use "var1 = 5", you use "SetVar1(5)".

Ad
Log in to vote
2
Answered by
W8X 95
9 years ago

It doesn't need to be delayed a different way, wait() is fine, a for loop automatically adds 1 so you don't need the line var1 = var1+1, and you should probably define var2 before you start the loop.

try this:

local var2
for var1=1,5 do
    print ("var1   " ..var1.."")
    wait(3)
    var2 = var1
    print ("var2   " ..var2.."")
end
Log in to vote
0
Answered by 9 years ago

If you're trying to print "1,2,3,4,5", then all you need is a for loop. It looks to me you're just not sure how to use the loop.

for var1 = 1,5 do
print(var1)
wait(1)
end

Answer this question