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

Help with using the wait method on a signal?

Asked by 10 years ago

So I found this cool way to a create custom event and I tried using the wait method on this event I made but it doesn't work why?

Image

Library = assert(LoadLibrary("RbxUtility"))
Signal = Library.CreateSignal()
    Signal:connect(function()
        print('This is a connection')
        print('Signal wait')
        Signal:wait()
        print('Done')
    end)
print('Signal fired')
Signal:fire()
print('Signal fired once,again')
Signal:fire()

Do I have to fire the signal twice in order to make the wait work and how can I just fire it once to print 'done'?

Output:

Signal fired

This is a connection

Signal wait

Signal fired once,again

Done

This is a connection

Signal wait

I just want it to print:

Signal fired

This is a connection

Signal wait

Done

I just want to fire the event once so it can print "done".

1 answer

Log in to vote
3
Answered by
Merely 2122 Moderation Voter Community Moderator
10 years ago

I ran the script in Studio in the command bar and it worked. You fired the event, and called Signal:wait(), so it's going to wait until the event fires again.

Here's a clearer example of how it works:

Library = assert(LoadLibrary("RbxUtility"))
Signal = Library.CreateSignal()

--in 2 seconds, fire the event
delay(2, function()
    print("Firing")
    Signal:fire()
end)

print("Waiting for fire")
Signal:wait()
print("Done waiting")

Output:

Waiting for fire

Firing

Done waiting

0
My own script isn't playing done in online. My place http://www.roblox.com/kevinnight45s-Place-Number-99-place?id=162582216 Check output in Server Console tab  kevinnight45 550 — 10y
0
Oh, delay is just like wait and do I have to put delay? kevinnight45 550 — 10y
2
Event objects don't have a 'state.' There's no way to tell if an event fired in the past. You can only tell if an event fires after you start listening to the event. Merely 2122 — 10y
2
So your problem is that you are firing the event, and then after it fires, you are waiting for it to fire again. But it never does. Merely 2122 — 10y
View all comments (11 more)
0
Not really i'm just wanting it to fire like a touched:wait() or like button1down:wait() and there is no purpose to this script I just wanted to learn about signals :s. kevinnight45 550 — 10y
0
How would I start to listen to a event? kevinnight45 550 — 10y
1
By nature, what event:wait() does is stop the current thread and waits for the event to be fired. Merely 2122 — 10y
0
So,it works differently with signals?  kevinnight45 550 — 10y
1
No, signals behave the same way as events. Merely 2122 — 10y
0
I'm sorry,but I'm really confused so why isn't the wait part working? kevinnight45 550 — 10y
1
It's working exactly as intended. The event is never being fired again. Think of it like firing a gunshot, and then waiting until you hear another gunshot. If no one fires another gunshot, you will be waiting forever. Merely 2122 — 10y
0
So I changed some stuff(Updated Code above) and managed to print Done but firing the signal two times did I do it right? kevinnight45 550 — 10y
1
How about you explain what you are trying to accomplish with your code? Merely 2122 — 10y
0
I'm trying to make it print "Signal Fired","This is a connection" and "Signal wait","Done" by just firing  the signal once and using the wait method.Like you did on your example kevinnight45 550 — 10y
Ad

Answer this question