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:
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 =).
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 =).