| 05-03-2007, 09:59 PM | #1 |
I was wondering if there was a thread and/or tutorial somewhere concerning the creation/useage of custom events. Either that, of if someone could just explain it to me. By custom events, I mean things such as this, in which KaTTaNa created a TriggerRegisterMouseClickInRegion event. Or is it something that's overwhemlingly complicated/tedious? |
| 05-03-2007, 11:08 PM | #2 |
I don't know of any tutorials, but custom events basically piggy-back off of native events and automate a certain aspect. For example, the even above creates trackables (which can detect mouse-clicks) within the specified rect and then assigns each rect to the given trigger. Other custom events can piggy-back off of systems using TriggerExecute() to the triggers with the events, every-time a certain event within the system occurs. The tediousness and complexity relates to exactly what you want to accomplish. |
| 05-03-2007, 11:15 PM | #3 |
your custrom register function adds a trigger to a data structure of some kind. (probobly a global array) Then you would use a periodic trigger, timer, existing events, ext. that 'create' in total your event. Then jsut loop throgh the array, evaluating (so conditions are checked) every trigger in the array. For removing triggers eassily from the list, take the last element in the array and put it in place of the removed element, and decrease the count by 1. (you will need to attatch a triggers index in the array to it somehow. probobly throgh game cache.) This does mean you have to call an additional cleanup function (otherwise dynamicly created triggers would cause your array to eventually hit the limit) This may not be the best way, but its a way. I could write up an example if you want ^^ |
| 05-04-2007, 01:00 AM | #4 | |
Quote:
|
| 05-04-2007, 01:54 AM | #5 |
JASS:globals trigger array udg_my_events_triggers integer udg_my_events_count = 0 endglobals function Register10Second takes trigger my_trig returns nothing set udg_my_events_triggers[udg_my_events_count] call SetHandleInt(my_trig, "bleh", udg_my_events_count) set udg_my_events_count = udg_my_events_count + 1 endfunction function Unregister10Second takes trigger my_trig returns nothing local integer trigger_index = GetHandleInt(my_trig, "bleh") set udg_my_events_triggers[trigger_index] = udg_my_events_triggers[udg_my_events_count - 1] set udg_my_events_triggers[udg_my_events_count - 1] = null endfunction function EventMakingFunction takes nothing returns nothing // call this function when the event you want happens. eg: use it as a callback to a timer started in Register10Second() with a 10 sec timeout local integer i = 0 loop exitwhen i == udg_my_events_count call ConditionalTriggerExecute(udg_my_events_triggers[i]) set i = i + 1 endloop endfunction //-------------------------------------------------------------------------- function MyTrigger_Actions takes nothing returns nothing // Do stuff call Unregister10Second(GetTriggeringTrigger()) call DestroyTrigger(GetTriggeringTrigger()) endfunction function Init_MyTrigger takes nothing returns nothing set gg_trg_MyTrigger = CreateTrigger() call TriggerAddAction(gg_trg_MyTrigger, function MyTrigger_Actions) call Register10Second(gg_trg_MyTrigger) endfunction I wrote this up kinda fast, so there may be errors. Also, no vJass for poor pyro =( *makes fun of this with the UDG prefix* Edit: Also, you can simulate event response functions by using globals that you set before excecuting all the triggers in the loop. Could wrap em in functions if you are so inclined. |
| 05-04-2007, 02:07 AM | #6 | |
Oh... *Nods* I get it; that's rather useful information actually. And you know what? Quote:
|
| 05-04-2007, 11:12 AM | #7 |
Your example isn't a 'custom event', it's just a function which organises the adding of events based on the given parameters. For actual custom events, that's far too vague, it depends entirely on what the event is (what it is responding to, whether that can be detected, if it's based on a map-specific system...). |
| 05-04-2007, 11:43 AM | #8 | |
Quote:
|
