• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Event v1.1

System code:
JASS:
//*************************************************************************************
//*
//*    Event by Almia
//*    JASS-alt of Nes Event
//*
//*************************************************************************************
//*
//*    Allows you to create your own events, but needs to be manually fired to trigger
//*    registered triggers and codes.
//*
//*    Event size is 2147483647( just a guess)
//*
//*************************************************************************************
//*
//*    API
//*
//*    function CreateEvent takes nothing returns integer
//*    function FireEvent takes integer ev returns nothing
//*    function TriggerRegisterEvent takes trigger t, integer ev returns nothing
//*    function RegisterEvent takes code c, integer ev returns nothing
//*
//*************************************************************************************
//*
//*   Credits
//*
//*       Nestharus
//*
//*************************************************************************************
function CreateEvent takes nothing returns integer
    set udg_Event_Count = udg_Event_Count + 1
    set udg_Events[udg_Event_Count] = CreateTrigger()
    return udg_Event_Count
endfunction

function FireEvent takes integer ev returns nothing
    set udg_Event_Events = I2R(ev)
    set udg_Event_Events = 0.0
    call TriggerEvaluate(udg_Events[ev])
endfunction

function TriggerRegisterEvent takes trigger t, integer ev returns nothing
    call TriggerRegisterVariableEvent(t, "udg_Event_Events", EQUAL, I2R(ev))
endfunction

function RegisterEvent takes code c, integer ev returns nothing
    call TriggerAddCondition(udg_Events[ev], Condition(c))
endfunction

Demo Code:
JASS:
function Hello takes nothing returns nothing
    call BJDebugMsg("Hello")
endfunction

function Hi takes nothing returns nothing
    call BJDebugMsg("Hi")
    call Hello()
endfunction

function InitTrig_Hello takes nothing returns nothing
    // Create Events
    local integer ev = CreateEvent()
    local integer ev2 = CreateEvent()
    // Register ev as function Hello's event
    call RegisterEvent(function Hello, ev)
    // Fire ev, executing function Hello and other function that has ev registered as their event.
    call FireEvent(ev)
    // Register ev2 as function Hi's event
    call RegisterEvent(function Hi, ev2)
    // Fire ev2, executing function Hello and other function that has ev2 registered as their event.
    call FireEvent(ev2)
endfunction

Credits:
- Nestharus

Note:
- This may conflict with Nestharus vJASS code.

Changelog:
- Optimized code.
Contents

Event v1.1 (Map)

Reviews
13:48, 13th Jun 2013 PurgeandFire: Approved. Useful for vanilla JASS'ers who want to use this. Probably too difficult for GUI'ers, but whatever. It works. Just a slight note, you say the event size is the integer cap. You can have as many...

Moderator

M

Moderator

13:48, 13th Jun 2013
PurgeandFire: Approved. Useful for vanilla JASS'ers who want to use this. Probably too difficult for GUI'ers, but whatever. It works.

Just a slight note, you say the event size is the integer cap. You can have as many conditions registered to one event as you want (until your comp can't handle it), but the maximum number of events is 8192 because of the index limit. That shouldn't matter though, since no one needs that many individual events.
 
Level 10
Joined
Aug 21, 2010
Messages
316
JASS:
function TriggerRegisterEvent takes trigger t, integer ev returns nothing
    call TriggerRegisterVariableEvent(t, "udg_Event_Events", EQUAL, I2R(ev))
endfunction

function RegisterEvent takes code c, integer ev returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterEvent(t, ev)
    call TriggerAddCondition(t, Condition(c))
    set t = null
endfunction

maybe...->

JASS:
function RegisterEvent takes code c, integer ev returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterVariableEvent(t, "udg_Event_Events", EQUAL, I2R(ev))
    call TriggerAddCondition(t, Filter(c))
    set t = null
endfunction

This is not enough
JASS:
function Hello takes nothing returns nothing
    call BJDebugMsg("Hello")
endfunction

function Hi takes nothing returns nothing
    call BJDebugMsg("Hi")
    call Hello()
endfunction

function InitTrig_Hello takes nothing returns nothing
    local integer ev = CreateEvent()
    local integer ev2 = CreateEvent()
    call RegisterEvent(function Hello, ev)
    call FireEvent(ev)
    call RegisterEvent(function Hi, ev2)
    call FireEvent(ev2)
endfunction

A lot of people here just will not understand how to use this,because this one example is not enough.
Show us some more examples.
 
Last edited:
Level 33
Joined
Apr 24, 2012
Messages
5,113
JASS:
function TriggerRegisterEvent takes trigger t, integer ev returns nothing
    call TriggerRegisterVariableEvent(t, "udg_Event_Events", EQUAL, I2R(ev))
endfunction

function RegisterEvent takes code c, integer ev returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterEvent(t, ev)
    call TriggerAddCondition(t, Condition(c))
    set t = null
endfunction

maybe...->

JASS:
function RegisterEvent takes code c, integer ev returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterVariableEvent(t, "udg_Event_Events", EQUAL, I2R(ev))
    call TriggerAddCondition(t, Filter(c))
    set t = null
endfunction

This is not enough
JASS:
function Hello takes nothing returns nothing
    call BJDebugMsg("Hello")
endfunction

function Hi takes nothing returns nothing
    call BJDebugMsg("Hi")
    call Hello()
endfunction

function InitTrig_Hello takes nothing returns nothing
    local integer ev = CreateEvent()
    local integer ev2 = CreateEvent()
    call RegisterEvent(function Hello, ev)
    call FireEvent(ev)
    call RegisterEvent(function Hi, ev2)
    call FireEvent(ev2)
endfunction

A lot of people here just will not understand how to use this,because this one example is not enough.
Show us some more examples.

Im too lazy to type codes that I have done before,so I just used the shortcut.

I'll add a documentation if you want.

So you are telling me that this allows you to use something like

function x is fired?
Certainly,yes. This system is just like how Unit Indexer works. Example, once an indexed unit enters,it fires the Indexed Event,if it dies, it fire the DeIndex event.

edit
Updated the demo's doc, but only in this resouce description.
 
Level 33
Joined
Apr 24, 2012
Messages
5,113
1. How would I choose which trigger I want the event for?

2. Would this work?
call RegisterEvent(function BJDebugMsg(string), CreateEvent())
2b if it works why not simply use the hook function?

1. You need to register the event you want to that trigger.
2. No, and it will cause Syntax Errors and you also need to cache the CreateEvent since you need to fire it manually( by FireEvent)
2b, because this is JASS not vJASS. hook is a vJASS feature. and also this is Event not an Event that detects if a function is executed(well, certainly that is a yes, if you use FireEvent, but those functions you created are included,but not the default BJs and natives.)
 
Let's say you make an event with CreateEvent(). When people register for the event, they will create a new trigger each time to register the same event, even if it is using the same CreateEvent() instance.

Instead, it should only use 1 trigger per CreateEvent() instance.

Atm, TriggerAddCondition(t, Condition(function x)) followed by TriggerEvaluate(t) beats this.
 
So if I register two conditions to 1 Event instance, it creates two triggers already??? It seems like a huge waste when I create multiple actions under the same Event...

You should make each Event instance have only one trigger each so that you'll have less Triggers firing when you have multiple registrations on the same Event instance...

That way it will be

Fire-> Retrieve Trigger -> Evaluate conditions

instead of the current way that is:

Fire -> Trigger1 -> Evaluate Condition
-> Trigger2 -> Evaluate Condition
-> And so on for each registrations using the same Event instance
 
Top