• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

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...
 
Level 13
Joined
Nov 7, 2014
Messages
571
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