• 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.
  • It's time for the first HD Modeling Contest of 2025. Join the theme discussion for Hive's HD Modeling Contest #7! Click here to post your idea!

[Solved] Structs: is there a "keyword" equivalent for methods?

Is there a way to do something like this?
JASS:
struct A
    private method methodA takes real x returns nothing

    private method methodB takes nothing returns nothing
        call methodA(0)
    endmethod

    private method methodC takes nothing returns nothing
        call methodB()
    endmethod

    private method methodA takes real x returns nothing
        call methodC()
    endmethod
endstruct

edit: This example would cause an infinite loop, but it's just an example. Point is, is there a way to "pre-declare" (I don't know the proper term for this) a method in a struct?

edit2: ok nevermind, apparently the order of the methods doesn't matter, you can always call on any member. please delete lol
 
Last edited:
Yep, that is supported with vJASS. :)

The one thing to note is that it isn't natively supported with standard JASS, unless you use ExecuteFunc() or triggers. So to support that feature, vJASS resorts to some trickery. It will wrap the function call in a trigger and pass some parameters via globals to execute it. For example:
JASS:
private methodB takes nothing returns nothing
    call methodA(0)
endmethod

private methodA takes real x returns nothing
    // ...
endmethod
Would roughly translate into something like this:
JASS:
globals
    trigger methodA_Trigger
    integer methodA_Parameter1
    real methodA_Parameter2
endglobals

function methodB takes integer instance returns nothing
    set methodA_Parameter1 = instance
    set methodA_Parameter2 = 0
    call TriggerEvaluate(methodA_Trigger)
endfunction

function methodA takes integer instance, real x returns nothing
    // ...
endfunction

function methodA_Wrapper takes nothing returns boolean
    call methodA(methodA_Parameter1, methodA_Parameter2)
    return false
endfunction

function SomeGeneratedInitializerFunction takes nothing returns nothing
    set methodA_Trigger = CreateTrigger()
    call TriggerAddCondition(methodA_Trigger, Condition(function methodA_Wrapper))
endfunction

This is just pseudocode, but it gets the point across. My main advice would be to always order your methods the standard JASS way where possible (put methods above ones that call it), unless you need it (your example is a good example of a case that "needs" it).

In the past, when I'd review some spells/systems there were a few people who would order their methods freely based off stylistic preference, not knowing that the underlying code is generating a bunch of triggers/globals just to support it. It's definitely a nice, easy optimization to do if you can afford it.
 
Top