• 🏆 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 Structs

Status
Not open for further replies.
Level 10
Joined
Sep 14, 2007
Messages
227
Code:
struct test
    integer array Con[10]

 static method create takes nothing returns thistype
    local thistype this = thistype.allocate()
    return this
 endmethod
endstruct

Code:
function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    test(1).Con[1]
    call DisplayTextToForce( GetPlayersAll(), I2S((test(1).Con[1])) )
    call DisplayTextToForce( GetPlayersAll(), I2S((test(2).Con[1])) )
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_002 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_002 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Untitled_Trigger_002, Player(0), "o", true )
    call TriggerAddAction( gg_trg_Untitled_Trigger_002, function Trig_Untitled_Trigger_002_Actions )
endfunction

Then i change (test(1).Con[1] = 1), somehow test(2).Con[1] become also 1. Maybe some one could help me with this problem or give me example how to create struct with array.
 
Last edited:
Level 11
Joined
Sep 30, 2009
Messages
697
The constructor takes no integer yet you provide it with one.

Am I blind or does he never use the constructor or has he changed his post?


@Topic:

to use array structs instead of normal structs just make a struct that extends array

JASS:
struct ArrayStruct extends array
endstruct

if you want to have arrays in a struct you do excactly what you did.
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Tc means the struct instance member Con as array obv. The constructor is not called in the shown code. But you would need to run the normal allocation method if you wanted to use member arrays since some variable is initialized there that is macroed inside the array's index.

JASS:
struct A
    integer array MyArray[10]

    method test takes nothing returns nothing
        set thistype(1).MyArray[5] = 13
    endmethod
endstruct

convertes to

JASS:
//JASSHelper struct globals:
constant integer si__A=1
integer si__A_F=0
integer si__A_I=0
integer array si__A_V
integer array s___A_MyArray
constant integer s___A_MyArray_size=10
integer array s__A_MyArray

endglobals


//Generated allocator of A
function s__A__allocate takes nothing returns integer
 local integer this=si__A_F
    if (this!=0) then
        set si__A_F=si__A_V[this]
    else
        set si__A_I=si__A_I+1
        set this=si__A_I
    endif
    if (this>818) then
        return 0
    endif
    set s__A_MyArray[this]=(this-1)*10
    set si__A_V[this]=-1
 return this
endfunction

function s__A_test takes integer this returns nothing
    set s___A_MyArray[s__A_MyArray[(1)]+5]=13
endfunction

Do not ask me why Jasshelper does not directly inline the constant size. This is bad for other allocation methods.
 
Status
Not open for further replies.
Top