| 08-05-2009, 01:24 AM | #1 |
so I tried something like this 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: JASS:call PD[i].setPlaying( true ) JASS:library PlayerData globals PlayerData PD endglobals struct PlayerData extends array private integer team private integer best_time private integer player_id private integer unit_count private integer lap_count private integer selector_num private boolean playing method setTeam takes integer team returns nothing set this.team = team endmethod method getTeam takes nothing returns integer return this.team endmethod //---------------------------------------------- method setTime takes integer time returns nothing set this.best_time = time endmethod method getTime takes nothing returns integer return this.best_time endmethod //---------------------------------------------- method setId takes integer newId returns nothing set this.player_id = newId endmethod method getId takes nothing returns integer return this.player_id endmethod //---------------------------------------------- method resetUnitCount takes nothing returns nothing set this.unit_count = 0 endmethod method addUnitCount takes nothing returns nothing set this.unit_count = this.unit_count + 1 endmethod method getUnitCount takes nothing returns integer return this.unit_count endmethod //---------------------------------------------- method resetLapCount takes nothing returns nothing set this.lap_count = 0 endmethod method addLapCount takes nothing returns nothing set this.lap_count = this.lap_count + 1 endmethod method getLapCount takes nothing returns nothing return this.lap_count endmethod //---------------------------------------------- method addSelectorNum takes nothing returns nothing set this.selector_num = this.selector_num + 1 endmethod method subSelectorNum takes nothing returns nothing set this.selector_num = this.selector_num - 1 endmethod method getSelectorNum takes nothing returns integer return this.selector_num endmethod //---------------------------------------------- method setPlaying takes nothing returns nothing set this.playing = true endmethod method isPlaying takes nothing returns boolean return this.playing endmethod //---------------------------------------------- method remakeGame takes nothing returns nothing local integer i = 0 loop set this.team = 0 set this.best_time = 0 set this.player_id = 0 set this.unit_count = 0 set this.lap_count = 0 set i = i + 1 exitwhen i == MAX_PLAYERS endloop endmethod endstruct endlibrary 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 |
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 |
Is there any way to get the index inside the methods? |
