• 🏆 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 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.
Top