• Check out the results of the Techtree Contest #19!
  • 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.
  • Create a void inspired texture for Warcraft 3 and enter Hive's 34th Texturing Contest: Void! Click here to enter!
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!

Array Of Structs, How to Acess

Status
Not open for further replies.
Level 12
Joined
Feb 23, 2008
Messages
587
SOVLED

Question: This prints out 5 , twice. Any Idea What I am Doing wrong?

Answer: I wasn't creating instances of the tracks, correctly.

JASS:
 //What Was Changed
           
           //Old
               //call r.myTracks[0].create()
               //call r.myTracks[1].create()
           //New          
               set r.myTracks[0] = r.myTracks[0].create()
               set r.myTracks[1] = r.myTracks[1].create()
JASS:
struct Track
        public integer x
        
        static method create takes nothing returns thistype 
        local thistype r = thistype.allocate()                     
            set r.x = 0

            return r
        endmethod
endstruct

struct Cart
    public integer x
endstruct

struct Rollercoaster
    Track array myTracks[1000]
    Cart array myCarts[8]
    integer y
    static method create takes nothing returns thistype 
        local thistype r = thistype.allocate()          
           //What Was Changed
           
           //Old
               //call r.myTracks[0].create()
               //call r.myTracks[1].create()
           //New          
               set r.myTracks[0] = r.myTracks[0].create()
               set r.myTracks[1] = r.myTracks[1].create()
            
            set r.y = 20

            return r
        endmethod
endstruct

JASS:
function CreateArrayOfPlayersLotsOfTracks takes nothing returns nothing
    
    local Rollercoaster array myPlayer
    
    call myPlayer[0].create()

    set myPlayer[0].myTracks[0].x = 10
    set myPlayer[0].myTracks[1].x = 5
    
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, I2S(myPlayer[0].myTracks[0].x))
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, I2S(myPlayer[0].myTracks[1].x))


endfunction


//===========================================================================
scope SetupGame initializer InitA 
    
    function  InitA takes nothing returns nothing
        
        call CreateArrayOfPlayersLotsOfTracks()
    endfunction
    
endscope

SOVLED
 
Last edited:
Status
Not open for further replies.
Back
Top