[vJASS] [Snippet] RealEvent


Code Moderator
Level 49
Sep 26, 2009
Bannar contacted me in regards to the Event library being remade into Trigger, moved offsite, having 15 requirements and not even having a standard API across resources anymore thanks to syntax changes over the years.

I wrote this small function for my DamageEngine GUI/vJass hybrid project which is still in the lab. But the standalone function is ready as there isn't much to it, despite that it conforms to all necessary capabilities of an event library.

library RealEvent
    Made by Bribe

    This is a unification of the real variable event in wc3 and clean vJass syntax.
    It is made to fill the void created by resources that need an event but want an API
    that works without requiring a bunch of libraries.

    Tiny API:
    CreateRealEventTrigger(string whichVariable, real whichValue, code whichFunction) -> trigger

    If you specify a code value, it automatically adds that as a condition,
    making this a nice one-liner that also returns the trigger in case you need it.

    Since JASS doesn't support pointers but values, the user will need to fire the
    event manually, via: 

    set realVariable = 0.00
    set realVariable = eventValue

    private trigger tempTrig

//You do not need the return value of this function if you have no intention of
//disabling/destroying this trigger from outside of it being run.
function CreateRealEventTrigger takes string variable, real value, code run returns trigger
    set tempTrig = CreateTrigger()
    call TriggerRegisterVariableEvent(tempTrig, variable, EQUAL, value)
    if run != null then
        call TriggerAddCondition(tempTrig, Filter(run))
    return tempTrig



Code Reviewer
Level 26
Mar 19, 2008
@Shadow Flux: You end up declaring that local everytime function is called. It's better to use static instead.

Vote for insta approve. As stated, many resources have been using old Event which has been drastically changed throughout the years. If one doesn't own his own copy of previous Event, there is no way for him to include that crucial for many systems library anymore. This means many resources available on hive actually do not work or require manual ingerention of user. New Event is not an option since it's not fully compatibile and most users are unlikely to implement so many custom resources just to achieve such a simple functionality.

However, old Event didnt allow user to access the trigger handle. All in all, Event was a simple, small wrapper around TriggerRegisterVariableEvent with trigger array addition. Let's be honest, calling events is not hard and most users have been adding "fire" method within their structs anyway.


Code Reviewer
Level 26
Mar 19, 2008
Precisely - anyone could. Problem is, the best, simplest Event has been removed by Nes. It's good to have similar snippet around on hive - allows users to google it more easily.
Of course some additional functionality could be added, but most people which require such thing will probably know what to do next/write their own thing.

Just add this to 'Small snippets' subforum if you think it doesn't belong here.
Level 17
Apr 27, 2008
Imho a such resource doesn't belong there.
It's wayyyyyyy to simple and for what, just less typing ?
The requirement is more annoying than the benefit.

I asked to graveyard LocalHelper and that was more complex.

So small code and snippets if you want but seriously that shouldn't be a requirement in any resource, optional if you want.