• 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.

Array of type code not allowed

Status
Not open for further replies.

EdgeOfChaos

E

EdgeOfChaos

This is always a really annoying error since it makes it so you can't use any code type in a Struct. This is a very simple workaround for it that at least lets you save and execute code in an array. If there's any better workaround I'd love to hear it, since I have to use a code array in a map I'm making:

JASS:
struct Code

    /**
    *   Used to store the code internally
    *   Code will be added as an action to
    *   this trigger, then executed as a trigger
    *   when called.
    */
    private trigger t
  
    public static method create takes code c returns thistype
        local thistype new = thistype.allocate()
        set new.t = CreateTrigger()
        call TriggerAddAction(new.t,c)
        return new
    endmethod
  
    public method destroy takes nothing returns nothing
        call DestroyTrigger(t)
        set t = null
    endmethod
  
    public method execute takes nothing returns nothing
        call TriggerExecute(t)
    endmethod
  
endstruct
Of course it won't let you use it as a code for an enumerator function or something like that...
 
Using the Typecast library:

JASS:
globals
    integer array my_funcs
    integer my_funcs_count
endglobals

function A takes nothing returns nothing
    call BJDebugMsg("A")
endfunction
function B takes nothing returns nothing
    call BJDebugMsg("B")
endfunction

function my_funcs_init takes nothing returns nothing
    set my_funcs[1] = C2I(function A)
    set my_funcs[2] = C2I(function B)
    set my_funcs_count = 2
endfunction

function call_my_funcs takes nothing returns nothing
    local integer i = 1
    local code my_func
    loop
        exitwhen i > my_funcs_count
        set my_func = I2C(my_funcs[i])
        call ForForce(bj_FORCE_PLAYER[0], my_func)
        set i = i + 1
    endloop
endfunction
 

EdgeOfChaos

E

EdgeOfChaos

Pretty cool. Didn't know about that typecasting stuff, thanks for that.

Could this be patched by Blizzard though? Just worried about using potential exploit stuff.
 
Status
Not open for further replies.
Top