Limited Trigger Recycling

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
First of all why bother recycling when you can Destroy and Create? Hm... I am not sure (given the much improved hardware these days) but I think if a handle type could be recycled it should (example: unit handles (projectiles, dummies, etc.), timers [of course =)], groups and I can't think of any other handle type right now). So recycling seams logical and what this snippet demonstrates is that the [ljass]trigger[/ljass] type can
also be recycled (kinda...). Recycled in the sense that it's event can be changed (although there's a "but").

The demo:
JASS:
globals
     eventid array triggers_eventids
endglobals

function TriggerSetEventId takes trigger t, eventid eid returns nothing
    set triggers_eventids[ModuloInteger(GetHandleId(t), 8190)] = eid
endfunction

globals
    trigger the_trigger_which_changes_its_event = null
endglobals

function action takes nothing returns nothing
    if triggers_eventids[ModuloInteger(GetHandleId(GetTriggeringTrigger()), 8190)] != GetTriggerEventId()  /* and other conditions */ then
        return
    endif

    call BJDebugMsg("boo")
endfunction

function change_event takes nothing returns nothing
    call TriggerRegisterPlayerEvent(the_trigger_which_changes_its_event, Player(0), EVENT_PLAYER_ARROW_UP_UP)
    call TriggerSetEventId(the_trigger_which_changes_its_event, EVENT_PLAYER_ARROW_UP_UP)
endfunction

function InitTrig_Melee_Initialization takes nothing returns nothing
    local trigger t = null
    // this trigger is just for the switching of the events for the other trigger with the long name =)
    set t = CreateTrigger()
    call TriggerRegisterPlayerEvent(t, Player(0), EVENT_PLAYER_END_CINEMATIC)
    call TriggerAddAction(t, function change_event)

    set the_trigger_which_changes_its_event = CreateTrigger()
    call TriggerRegisterPlayerEvent(the_trigger_which_changes_its_event, Player(0), EVENT_PLAYER_ARROW_DOWN_UP)
    call TriggerSetEventId(the_trigger_which_changes_its_event, EVENT_PLAYER_ARROW_DOWN_UP)
    call TriggerAddAction(the_trigger_which_changes_its_event, function action)
endfunction


I will explain what's happening even if it's obvious. When the map loads and the player presses the down key and releases it
the "boo" is displayed, but when he presses the escape key the down key now stops working and the up key starts printing "boo".
In other words the event has changed.

But what is the "but" I was writing about above? Well what if the events are similar but not quite (example: the first event is paladin enters city, and the second is paladin enters village), now what happens is that if try to change the first for the second, we can't because we can no longer differentiate between the events, unfortunately.

I am posting this for someone to help make the [ljass]trigger[/ljass] type on of those few worthy of recycling =).
 

tooltiperror

Super Moderator
Reaction score
231
I can't see a reason of why would you destroy a trigger

Because it's useless space and a waste of Handle Id if it is not being reused.

I can't see a reason you would destroy a trigger and recreate it.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
I am not sure if this will help (and this is probably well known) but these two exist:

[ljass]native SaveTriggerEventHandle takes hashtable table, integer parentKey, integer childKey, event whichEvent returns boolean[/ljass]
[ljass]native LoadTriggerEventHandle takes hashtable table, integer parentKey, integer childKey returns event[/ljass]

Well couldn't think of anything using them so I wonder why Blizzard even included them instead of the more reasonable (I think)
[ljass]native TriggerRemoveEvent takes trigger t, event e returns nothing[/ljass]
[ljass]native TriggerClearEvents takes trigger t returns nothing[/ljass]
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
Yeah your method most likely will end up being inefficient due to the lack of unregistering/destroying events. If you really care about handle count then you can always destroy triggers that you are no longer using. (Although, just note that some people suggest that destroying triggers should not be done [albeit without giving any reasoning])

I recommend you just use something like GTrigger, and then for all other events just make triggers as you normally would. In general, a lot of the precautions make minimal difference, it is usually just meant to be taken into consideration for submitting systems as they should run as smoothly as possible. Of course, with higher-end systems, a lot of that kind of stuff doesn't matter in the end, but it is just good coding practice.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top