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

How do you make a wait() only effect a part of a script?

Asked by 9 years ago

I want to make a script that allows the player to create lightning, but I want to a a charge function. The only problem is that I would need a wait for ever single time it charged up, but that wait would interfere with the rest of the script.

0
or maybe making the recharge a seperate script connor12260311 383 — 9y
0
If you post the script, we can help out. Chronomad 180 — 9y

2 answers

Log in to vote
0
Answered by 9 years ago

To run separate pieces of code at the same time in a script, you can use Coroutines. These allow you to run code on separate threads in the same script, so the code can still send and receive information in the same script while separate pieces of code can run independently.

Example:

print(1)

coroutine.resume(coroutine.create(function()
    wait(1)
    print(3)
end))

print(2)

--Output: 1 2 3
0
Thanks aquathorn321 that was exactly what I was looking for gaberdell 71 — 9y
Ad
Log in to vote
0
Answered by
Scriptecx 124
9 years ago

If you are wanting to let the lightning charge up before you can use it again, then use an if statement to make sure that the lighting charge value is what you want it to be before you can use it again. This is also called a debounce.

Answer this question