Game Development Community

Trying to use datablocks

by J Sears · in Torque Game Builder · 04/15/2007 (12:52 pm) · 5 replies

I'm trying to learn how to use datablocks correctly so that when my program gets more complex and multiplayer I can have it work smoothly. For now I'm figuring out how to do the program all single player and then figure out how to get it into multiplayer.

So I'm trying to make a datablock that I can use to store each players bid, tricks and score and I tried to do it like this

datablock players(allPlayers)
{
bid=0;
tricks=0;
score=0;
};

what am I doing wrong? I get an error on this datablock when the mission loads.

#1
04/15/2007 (8:21 pm)
J Sears, don't use datablocks unless they are scene objects ...

%playerBid = new ScriptObject() { bid = 0; tricks = 0; score = 0; };

Datablocks are for reusable field definitions, not for defining class outlines ... they are also Scene Object specific, as far as I know ... haven't run into a generic SimObject Datablock ... and ScriptObject doesn't have a config field, actually, it doesn't have any default fields ... and is just a simple instance of SimObject, at it's bare basics ...

I would just toss the above ScriptObject creation code in the Player::onLevelLoaded() or Player::onAdd() code when the player object is created ... but keep in mind, TGB doesn't translate objects for you like TGE does ... so be careful what your sending over the network about your players in TGB ... :)
#2
04/16/2007 (3:27 pm)
Ya that's what throwing me off, in my tge project I found it a lot easier to add values for each specific player and it's proving to be trickier then I thought for TGB, thanks for the tip about scriptobjects I will look into learning more about those.
#3
04/16/2007 (3:48 pm)
@J, you can define a 'playerDatablock', which would be more like;

new t2dSceneObjectDatablock(playerDatablock)
{
  bid = 0;
  tricks = 0;
  score = 0;
};

and this can be assigned to the scene object representing your player ... which would be more 'tge' like ... TGE has a 'player' object (afaik), where as ... TGB does not ... TGB also does not have nearly as many datablock base classes as TGE does ... but all the key datablock base classes are in the TGB Reference ...
#4
04/16/2007 (5:50 pm)
Ya that's what I was trying to do I had tried is as just new datablock though, but as I was thinking about it today it seems a very easy way for me to do what I want would be with global arrays of bid tricks and score with each player having their spot in the array. It may not be the best way to do it but it seems that it will be very easy to work with. Guess I'll find out when I try to get the multiplayer working
#5
04/16/2007 (5:52 pm)
Hrm, k ... let me know what you wind up with, eh?