Arrays and Data Structure Question
by TerrenceB · in Torque Game Builder · 11/08/2009 (12:29 pm) · 1 replies
Hi All,
I am not a programmer, but I can read some code. I'm spending a few hours a day with TGB, but I've got a long way to go.
Anyway, the game I'll be focusing on is a TBS with a lot of data to keep track of.
For development the game map will only have a few Territories, but later there will be many. Each Territory will have a couple dozen Variables, and then there are Variables to track for the Empire, for Leader Units, etc. etc..
A lot of the posts I've been reading through are pretty dated so I don't know if there are new opinions on the best way to store and use this data. Keeping in mind that it will be multiplayer, player vs AI or player vs player.
One post was talking about faking arrays by storing them in Script Objects or Simobjects. I imagine most of the arrays I need will have to be 2d arrays.
Any thoughts on this, or applicable articles would be very helpful.
I want to have the Data Structure fully figured out from the beginning, and actually understand the mechanics so I can use it. ;)
Thanks
Terrence
I am not a programmer, but I can read some code. I'm spending a few hours a day with TGB, but I've got a long way to go.
Anyway, the game I'll be focusing on is a TBS with a lot of data to keep track of.
For development the game map will only have a few Territories, but later there will be many. Each Territory will have a couple dozen Variables, and then there are Variables to track for the Empire, for Leader Units, etc. etc..
A lot of the posts I've been reading through are pretty dated so I don't know if there are new opinions on the best way to store and use this data. Keeping in mind that it will be multiplayer, player vs AI or player vs player.
One post was talking about faking arrays by storing them in Script Objects or Simobjects. I imagine most of the arrays I need will have to be 2d arrays.
Any thoughts on this, or applicable articles would be very helpful.
I want to have the Data Structure fully figured out from the beginning, and actually understand the mechanics so I can use it. ;)
Thanks
Terrence
Associate William Lee Sims
Machine Code Games
Typically, for a first cut, I'll just create a ScriptObject, and store my information in there.
new ScriptObject(TheWorld); for( %x = 0; %x < 5; %x++ ) { for( %y = 0; %y < 5; %y++ ) { TheWorld.terrain[%x,%y] = "Plain"; TheWorld.elevation[%x,%y] = 0; } }If you want to get REALLY fancy, you can make subclasses.
new ScriptObject(TheWorld); function TerrainNode::onAdd( %this ) { %this.type= "Plain"; %this.elevation = 0; } for( %x = 0; %x < 5; %x++ ) { for( %y = 0; %y < 5; %y++ ) { TheWorld.terrain[%x,%y] = new ScriptObject() { class = TerrainNode; }; } }There are probably a handful of really good ways to do this, and dozens of acceptable ways. It's comes down to this: what will you be comfortable with?
The only real advice I can give is to make an interface that will get you your information from whatever structure you keep it in without you directly accessing the innards. Then, if you need to optimize it (say, by converting it to code), it'll be trivial.
function TheWorld::terrainType( %this, %x, %y ) { // If done the first way: return %this.terrain[%x,%y]; // If done the second way: return %this.terrain[%x,%y].type; }None of the previous code was tested. Please do not expect it to be production code.