Can I create a custom event?

zhenzh
Posts: 50
Joined: Fri Apr 17, 2020 2:23 am

Re: Can I create a custom event?

Post by zhenzh »

I see. But the manually raising event inside function introduces a new issue to be resolved.
Invoking raiseEvent() in my case is equal to invoking send() directly (raiseEvent->wait_event->send)
Then, the function should look like:

Code: Select all

function wait_line(pattern, action)
    thread = coroutin.running()
    tempTrigger(pattern, [[wait_resume()]], 1)
    send(action)
    return coroutin.yield()
end
We expect the regular flow should be
trigger create -> send action -> coroutin.yield -> pattern coming(get response for send) -> trigger fired -> resume
While for some unexpected reason(network, server/client cpu and etc.), there may be chance the flow becomes
trigger create -> send action -> pattern coming(mud server response as fast as possible) -> trigger fired -> resume(nothing occurr as yield has not come) -> coroutin.yield
If the second case occur, the wait_line will trap in waiting forever.

User avatar
Vadi
Posts: 4852
Joined: Sat Mar 14, 2009 3:13 pm

Re: Can I create a custom event?

Post by Vadi »

Remember you can also pass closures/anonymous functions to tempTrigger, maybe that helps?

zhenzh
Posts: 50
Joined: Fri Apr 17, 2020 2:23 am

Re: Can I create a custom event?

Post by zhenzh »

Finially I get ride of using event and use a loop instead.
Attached my package.
Attachments
wait-and-wait-line.xml
(1.93 KiB) Downloaded 39 times

User avatar
Vadi
Posts: 4852
Joined: Sat Mar 14, 2009 3:13 pm

Re: Can I create a custom event?

Post by Vadi »

Nice! and some examples on how to use? With screenshots would be good.

If you could make a new thread in the scripts forum, that'd help people find it a lot easier.

zhenzh
Posts: 50
Joined: Fri Apr 17, 2020 2:23 am

Re: Can I create a custom event?

Post by zhenzh »

Well, I'll share it in script forum with usage :)

Post Reply