ScriptObject Instancing
by Drew -Gaiiden- Sikora · in Torque Game Builder · 07/28/2005 (1:41 am) · 22 replies
I just wanted to know if this was the best way to do this. It took quite a bit of effort to come up with this, I still haven't found the difinitive resource for ScriptObjects, I've just managed to accumulate knowledge from various posts around these forums.
new ScriptObject(Player)
{
score = 0;
hasSpecialBlock = false;
isLoaded = false;
...
};
$playerOne = new ScriptObject()
{
type = $PLAYER_ONE;
class = Player;
};
$playerTwo = new ScriptObject()
{
type = $PLAYER_TWO;
class = Player;
};
function Player::loadPlayer(%this)
{
// stuff
}Basically what I've done is the equivilant of (in C++)class Player
{
public:
int score = 0;
bool hasSpecialBlock = false;
bool is Loaded = false;
void loadPlayer();
};
Player* playerOne = new Player;
Player* playerTwo = new Player;This is the only way I could think of doing it, though if there is a better way I'd like to know. If not then hopefully this'll be of help to others as lost as I was for a time :P
#22
Anyway, glad your problems are now sorted.
08/03/2005 (1:35 pm)
Just to be sure, I did a quick search on variable scope and found that the Torque Documentation kind of indirectly implies that there is bock scope yet then gives an example that demonstrates that this isn't the case!!!for(0; %a < 5; %a++)
{
echo(%a);
}
echo(%a);Anyway, glad your problems are now sorted.
Torque Owner Drew -Gaiiden- Sikora