• 🏆 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 within , a Array of structs. Any Idea?

Status
Not open for further replies.
Level 12
Joined
Feb 23, 2008
Messages
587
I am trying to create an array of structs called players.
Also in players I am trying to have in array of structs called tracks.
Each Track will likely have 6-8+ values. And I want to be able to have 1000 tracks per player for 8 players.

I cant seem to get the syntax right, that and I don't fully understand what is allowed.

Any Idea what I am doing wrong, Or whats possible?
I will likely need to extend the size latter on.


JASS:
function CreatePlayers takes nothing returns nothing
    
    globals
        Players myPlayers 
    endglobals 
    
    //How Do I Access Tracks from with in Player??

endfunction

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


JASS:
library MyLibary
    
    struct Tracks extends array
    

        //Variables
        private integer x
        
        //You dont have to put public
        public integer y
        
        //Defualt values (You cant have a constuctor) 
         method default takes nothing returns nothing 
             set this.x = 0
         endmethod
        
        //Get
        method getX takes nothing returns integer 
            return this.x
        endmethod
        
        //Set
        method setX takes integer x returns nothing 
            set this.x = x
        endmethod
        
        //Action
        method addFiveToX takes nothing returns nothing 
            set .x = .x + 5
        endmethod
    
        
    endstruct
    
    struct Players extends array
                
        Tracks tracks 
        
        private integer totalTracks
        
        //Get
        method getTotalTracks takes nothing returns integer 
            return this.totalTracks
        endmethod
       
    endstruct
endlibrary
 
Level 12
Joined
Feb 23, 2008
Messages
587
What do I need to learn to do my first choice? Is it possible? Also How.

I Understand array struct 2d arrays, But thats my last choice. Can anyone help me with one of my top two choices?

Player Object Data

Person(struct)
-Track(struct)
-Cart(struct)
-Camera(struct)
-Unit(struct)
-Info(struct)

The Way I would Prefer For it to work

First Choice
person[x].tracks.getTrackvalues(x)
person[x].tracks.addTrack(x,y,z,xyangle,Modeltype)
person[x].tracks.getTotalTracks()

Second Choice
track[playerNum].getTrackvalues(x)
track[playerNum].addTrack(x,y,z,xyangle,Modeltype)
track[playerNum].getTotalTracks()

Third Choice
person[x].track[x].getTrackvalues()
person[x].track[x].CreateTrack(x,y,z,xyangle,Modeltype)
person[x].gettotalTracks()

Forth Choice
track[playerNum][x].getTrackvalues()
track[playerNum][x].CreateTrack(x,y,z,xyangle,Modeltype)
track[playerNum][x].gettotalTracks()

Currently Working
Currently I have none of my choices working, But I am going to see if i can get Ciebron 2d Array to work.
 
Last edited:
Level 13
Joined
Mar 16, 2008
Messages
941
JassHelper online manual says you can:
http://www.wc3c.net/vexorian/jasshelpermanual.html#arrmemb

JASS:
struct Players extends array

  // 20 = array size
    Tracks array tracks[20]

endstruct

You'll access it by player.tracks[integer]
If you read carefully, you see that Vex' example doesn't extend array.
Structs that extends array can't have arrays inside, it's mentioned somewhere.

Certain issues with array structs: You cannot declare default values (they would automatically be zero, null or false depending on the type of the member) , you cannot declare onDestroy (it would be pointless), you cannot use .allocate or .destroy, you cannot have array members.
 
Level 4
Joined
Jan 27, 2010
Messages
133
Oh, I see. But he could just omit the "extends array", and make a separate array for the players...

JASS:
globals
    Players array players
endglobals

struct Players // does NOT extend array :P
    Tracks array tracks[20]
endstruct

function Init 
    set players[0] = ...
    set players[1] = ...
endfunction

This would give him the preferable syntax:
p[].tracks[]
 
Level 13
Joined
Mar 16, 2008
Messages
941
The syntax would be the same, but he would deal with allocating,
creating and in theory destroying the structs.
A struct that extends array has more "features" then just the syntax.
They can't get allocated (and so on) because they behave like normal arrays,
but the advantage is the readability and order of them.
If he just wants the syntax, your method is "perfect",
but if he wants to use them as normal arrays, its impossible.
However, if it's realy used for players, allocating them at map-init
should work the same.
 
Status
Not open for further replies.
Top