PDA

View Full Version : Event Serializing and TriggerEvent



Dstructr
April 16th, 2006, 04:22 AM
Lets say i have this external event:
"ExtEvent"

"ExtEvent" triggers a script and does this:

if pld1 == "A" then
myglobalvar = 1
TriggerEvent("IntAEvent", 18) --Which Uses myglobalvar
else if pld1 == "B" then
myglobalvar = 2
TriggerEvent("IntBEvent", 18) --Which Uses myglobalvar
end

So if these events are triggered with delay betweeen:
"ExtEvent" "A"
(Ext Sleep 1000)
"ExtEvent" "B"

The girder logger says:
ExtEvent "A"
IntAEvent (Uses myGlobalVar = 1)
ExtEvent "B"
IntBEvent (Uses myGlobalVar = 2)
This works as a dream.

But if the events are sent without delay at all:
"ExtEvent" "A"
(No Ext Sleep)
"ExtEvent" "B"

The girder logger says:
ExtEvent "A"
ExtEvent "B"
IntAEvent (Uses myGlobalVar = 2)
IntBEvent (Uses myGlobalVar = 2)

Now this doesnt work, when IntAEvent and IntBEvent is fired
the global var is 2 in both cases.......

So why isnt the events serialized ????

And how can i get around this ?
Are there any other way to call a command without using TriggerEvent ?
Or maybe other ways to call a plugin command without using a command.

Global vars are the only way i can communicate with the plugin i'm trying to control..

I need the events to be serialized, I'm lost......

Mark F
April 17th, 2006, 09:37 AM
Why are you re-scheduling an event after setting the global variable? Why not do the rest of the event processing after setting the global variable value? This will force the serialization you are looking for.

The problem you are seeing is the multi-threaded nature of Girder. The enqueing of ExtEvent is asynchronous from the processing of that event. In this case, ExtEvent B is enqued before the LUA code for the prior event, TriggerEvent("IntAEvent", 18 ), executes.

Instead of using a script command as the target of the "ExtEvent", use a multi-command. The multi-command could use the switch plugin to choose one of multiple command targets based on the value of pld1. The first command of each command traget (they would also be multi-commands) could set the value of myglobalvar and the rest of the commands would be the same as what are currently in the commands you show as IntAEvent and IntBEvent.

Does this make sense?

Dstructr
April 17th, 2006, 11:08 AM
Dont worry about it, i found the source for the plugin and rewrote it to
use the payload params when the event is triggered.
Instead of reading the global vars when the event was triggered.
Easyer, cleaner and everything is serialized properly.

I didnt know about the switch plugin :).

Dst