HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

methods extending array

08-05-2009, 01:24 AM#1
Joker
so I tried something like this
Collapse from jasshelper manual:
struct playerdata extends array //syntax to declare an array struct
    integer a
    integer b
    integer c
endstruct

function init takes nothing returns nothing
 local playerdata pd

    set playerdata[3].a=12  //modifying player 3's fields.
    set playerdata[3].b=34  //notice it behaves as a global array
    set playerdata[3].c=500

    set pd=playerdata[4]
    set pd.a=17             //modifying player 4's fields.
    set pd.b=111            //yep, this is also valid
    set pd.c=501
endfunction

function updatePlayerStuff takes player p returns nothing
 local integer i=GetPlayerId(p)

    //some random function.
    set playerdata[i].a=playerdata[i].b

endfunction

Instead of a local, I used a global and it gives me an error saying pd is not an array.

Heres my code:
Expand JASS:

Expand JASS:

I tried setting PD to an array, but then it give's me another error saying I'm not allowed to assign method values or of that sort.
08-05-2009, 08:37 AM#2
TriggerHappy
I'm not sure thats what making your struct an array does that. But you can do something like this;

set playerdata(3).a=12

That will set a (of the third instance of your struct) to 12.
08-16-2009, 08:28 PM#3
Joker
Is there any way to get the index inside the methods?
methods extending array - Wc3C.net