Snippet Code

Azlier

Old World Ghost
Reaction score
461
You guys remember the now broken CodeVar right? Right.

This does everything that CodeVar could do except for returning the function originally passed to it. Isn't that magical?

Also contains a silly userData integer for you to use.

Note that desyncs may happen to Mac users should you use .evaluate on a function not returning a boolean.

JASS:
struct Code

    private static hashtable HT = InitHashtable()
    private trigger T = CreateTrigger()
    
    private static boolexpr B
    private static thistype D1
    private static thistype D2
    
    integer userData
    
    static method get takes code c returns thistype
        set .B = Filter(c)
        set .D1 = GetHandleId(.B)
        set .D2 = LoadInteger(.HT, .D1, 0)
        if .D2 == 0 then
            set .D2 = thistype.allocate()
            call TriggerAddAction(.D2.T, c)
            call TriggerAddCondition(.D2.T, .B)
            call SaveInteger(.HT, .D1, 0, .D2)
        endif
        return .D2
    endmethod
    
    method execute takes nothing returns nothing
        call TriggerExecute(.T)
    endmethod
    
    method evaluate takes nothing returns boolean
        return TriggerEvaluate(.T)
    endmethod
    
endstruct


This can be used like vJass' function interfaces without the arguments. I also predict it to be faster, really.
 

Jesus4Lyf

Good Idea™
Reaction score
397
Lol, that's not faster!

Besides, it's unfortunately redundant. In vJass, you can pass around functions as objects directly and call .execute and .evaluate... You can even pass parameters using function interfaces. :p

The codevar thing was only really useful because it could return the code (and because it provided nice syntax to me for haxxing up some bytecode magic, and hey look, patch 1.24...).
 

Azlier

Old World Ghost
Reaction score
461
CodeVar pretty much caused patch 1.24.

>Lol, that's not faster!
I'm talking about .execute and .evaluate. vJass' function interfaces use TriggerExecute and TriggerEvaluate, but there's also a middleman function that handles arguments, last I checked. So, shouldn't my .execute and .evaluate's be faster?
 

Azlier

Old World Ghost
Reaction score
461
If it's not a snippet, what is it? Do we need a word for something smaller than a snippet? Say, a puppet? A muppet? A misfit?
 

Azlier

Old World Ghost
Reaction score
461
I could actually write a Trigger struct that had "actions" and "conditions" made of Codes :p. Including GetCalledCode, that might be nice.

JASS:
struct Code extends array
    private static trigger t
    static method get takes code c returns trigger
        set .t=CreateTrigger()
        call TriggerAddAction(.t,Filter(c))
        call TriggerAddCondition(.t,c)
        return .t
    endmethod
endstruct

How do I keep an array of that to fire at any time? :confused:
 

Azlier

Old World Ghost
Reaction score
461
But that ruins all the fun :(.
 

Azlier

Old World Ghost
Reaction score
461
But hey, we can attach to code again :p.
 

Azlier

Old World Ghost
Reaction score
461
Nope, it's useless for all purposes other than attaching to code. Which is useless. :thup:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top