• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Event emulation

Status
Not open for further replies.
Level 3
Joined
Jan 29, 2021
Messages
34
Hello guys. Question is simple though could look strange- is it possible to create event without actually creating it?
What this dude is talking about you may ask. Okey, lets make an example-
If I press keyboard left arrow, the new playerEvent LEFTARROWKEYDOWN is created(sorry for wrong constant name, I'm typing from the phone). Is it it possible to create the same event by pressing Enter and typing for example "left", so kind of faking it?
 
You could simulate an event by
  1. Creating a class/struct that specifically manages a collection of triggerconditions such that they will all fire when a certain method of that class/struct is invoked.

  2. Register your desired function to an instance of the aforementioned class.

  3. Register a trigger to your desired "native" event.

  4. While the trigger is firing, invoke the method in #1 using the instance from #2.
In pseudo-code:
JASS:
// Creating the class
struct Event
    static method create()
        this.trigger = CreateTrigger()
        return this
    end
    method fire()
        TriggerEvaluate(this.trigger)
    end
    method register(code func)
        TriggerAddCondition(this.trigger, Condition(func))        
    end
end

// Having the trigger run at a specific "native" event
onInit
    local trigger trig = CreateTrigger()
    local Event ev    = Event.create()
    TriggerRegisterSomeEvent(trig, ...)
    TriggerAddCondition(trig, Condition(function()
        // Let the event run at this point
        ev.fire()
    end)
end
 
Level 3
Joined
Jan 29, 2021
Messages
34
Okey, reasonable, but if Im talking about pure Jass2, not VJass, how to change it? Does Jass support structs?
 
Status
Not open for further replies.
Top