• Check out the results of the Techtree Contest #19!
  • Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Nested RegisterVariableEvents error

Level 18
Joined
Mar 21, 2011
Messages
1,622
Hi guys,
i am using a few RegisterVariableEvents in my map to create custom events. This is the base function:
JASS:
    function RegisterEvent takes string varName, code c returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterVariableEvent(t, varName, EQUAL, 1.0)
        call TriggerAddCondition(t, Filter(c))
        set t = null
    endfunction
To trigger the custom event, i do this for example:
JASS:
        method operator coins= takes integer amount returns nothing
            if amount < 0 then
                set amount = 0
            endif
            set this.vCoins = amount
            set CoinChangeController = this
            set EVENT_CONTROLLER_COINCHANGE = 0.0
            set EVENT_CONTROLLER_COINCHANGE = 1.0
            set EVENT_CONTROLLER_COINCHANGE = 0.0
        endmethod
Initialization:
JASS:
call RegisterEvent("EVENT_CONTROLLER_COINCHANGE", function thistype.onCoinChange)

I have a few other custom events, like a custom "A unit dies"-Event. Now, when i create a trigger with the "unit dies" event, and the function called triggers another custom event, like a coin change, it will never jump back to all the other "on death" events.

Example:
-> i have initialized three "On Death"-Events.
-> a unit dies -> event variable is set, first of the three events is fired.
-> first onDeath function is called
-> now the second initialized "On Death"-event is fired.
-> second onDeath function is called and contains a coin change, so this is executed:
JASS:
set EVENT_CONTROLLER_COINCHANGE = 0.0
set EVENT_CONTROLLER_COINCHANGE = 1.0
set EVENT_CONTROLLER_COINCHANGE = 0.0
-> before the last onDeath event is fired, all the CoinChange events are fired (lets say there is only one CoinChange event)
-> onCoinChange function is called
-> and here it stops, the last onDeath function will never be called.

I hope it is somewhat understandable what i am trying to say. Is there an easy fix for that? Thanks in advance.
 
This is possibly a limitation with how such events are implemented. The solution might be to implement a queue to hold requested firings of custom events and fire all handles for a single event before moving onto any events that were fired by those handlers.

The flow would look somewhat like this:
-> i have initialized three "On Death"-Events.
-> a unit dies -> an appropriate event descriptor frame is queued onto the custom event request queue and the processing trigger is turned on.
-> the processing trigger with a periodic timeout of 0 is fired and it pulls the front event descriptor frame from the custom event request queue and sets the appropriate event variables.
-> first onDeath function is called
-> now the second initialized "On Death"-event is fired.
-> second onDeath function is called and contains a coin change.
-> coin change -> an appropriate event descriptor frame is queued onto the custom event request queue and the processing trigger is turned on.
-> third onDeath function is called.
-> the processing trigger with a periodic timeout of 0 is fired and it pulls the front event descriptor frame from the custom event request queue and sets the appropriate event variables.
-> onCoinChange function is called
-> the processing trigger with a periodic timeout of 0 is fired but the custom event request queue is empty so the processing trigger is turned off and returns (does nothing else).
 
Back
Top