Game Development Community

Datablock fun! (Sort of)

by Aaron Murray · in Torque Game Engine · 08/28/2001 (3:19 pm) · 9 replies

Okay, this is going to end up being a two question question, so here's the first...

I'm trying to create a new class called Helper which is derived from ShapeBase. I took another class (StaticShape I believe) and copied the code from that into a new file and renamed all instances of StaticShape to Helper in the header and cc file. I'm thinking right now that I'm cool and all, so I go on and make a script file for my helper containing the definition of a datablock like so "datablock HelperData(TestMinion)" and then I fill it in with a few members like className, shapeFile and a few other things that from my own testing don't seem to be important in the remedying of my problem. Anyways, I now go and open up server/scripts/commands.cs and right at the end I slap in this handsome piece of script...

function serverCmdAddHelper(%client)
{
// Create the player object
%helper = new Helper() {
dataBlock = TestMinion;
};
MissionCleanup.add(%helper);

%helper.setTransform( %client.player.getEyeTransform() );

}

(Hope that turns out alright in the post, I copied+pasted)

Okey dokey, so... Now I'm getting excited and I start up the example program, start a game, pull down the console and type in "commandtoserver('AddHelper');" and then boom! All of a sudden I get this fancy looking error message which reads "Object 'TestMinion' is not a member of the 'GameBaseData' data block class" and then some other errors follow it, but I'm pretty sure that this is the big one. So, anyways, nothing ends up happening after I type in that console command aside from the error, and I was left searching for reasons for this error message. The main thing which baffled me the most is the fact that I copied everything from the StaticShape files, and renamed them, so I can't figure out where else to look. Anyways, any help is appreciated, thanks!



Second of all, this is a more general question, but these ShapeBase objects, what kind of things should they be the base for? I'm assuming they would be the base for all types of things that involve a model and are rendered in the game, but it contains quite a few more members (Like mEnergy...) that seem to imply that ShapeBase should be the base for only objects that move around and interact, like players. So anyways, a little bit of clearing up here would be nice.


Thanks a bunch for any replies!

#1
08/29/2001 (10:00 am)
From what you describe, it appears to be a problem with the TestMinion object. You're assigning it as the helper object's datablock, but what is it? You left that part out :)

ShapeBase was originally intended to be the base class for all objects that have models. While developing T2, the class ended up with some features it probably shouldn't have, energy being one of them.
#2
08/29/2001 (5:22 pm)
Thanks for the clarification on the ShapeBase, it helped a lot. (The updated docs helped too... Keep up the good work!)

About your first answer though, I'm not sure exactly what you mean. It is defined in another script file that is being executed as "datablock HelperData(TestMinion)" and it is filled in. HelperData is declared and implemented in the code, since I used the StaticShape files.

Thanks for the response though!
#3
08/29/2001 (6:27 pm)
Are you sure the script file that includes the TestMinion datablock definition is being executed? and that there were no errors?

The datablock = TestMinion; line is testing to make sure that the name "TestMinion" represents a datablock object. So either it's not really a datablock object, not derived from the GameBaseData base class (and it sounds like you've set that up correctly), or it hasn't been defined at run time.
#4
08/29/2001 (8:12 pm)
Hmmm, although I'm not the most experienced person when it comes to the V12 scripts, I'm pretty sure there's no errors, since a .dso file IS being created for the script file. I've also tried moving the datablock definition out of it's own file and stuck it right above the function that uses it, with the same results. In the case that I'm overlooking potential errors, here is exactly what was in my Helper.cs file (And also above the function that used it)...

datablock HelperData(TestMinion)
{

className = Minion;
catagory = "Misc";

shapeFile = "data/shapes/player/player.dts";
debrisShapeName = "data/shapes/player/debris_player.dts";
debris = playerDebris;

aiAvoidThis = true;

mass = 90;
drag = 0.3;
maxdrag = 0.4;
density = 10;
maxDamage = 0.66;
maxEnergy = 60;
repairRate = 0.0033;
energyPerDamagePoint = 75.0;

};



I'm not sure what you mean by defined at run-time, unless you mean the executable's run-time where it's defined in the script's... uhh... initialization time... But in any case, I *think* it's implemented fine in the script as well, since I loosely followed the Player's LightMaleHumanArmor datablock, and there were only two references for that in all the scripts... Its definition and it's assignment to a newly created Player datablock.

Anyways, if you don't have an answer that this new information helps you immediately think of, it's okay if you just leave this topic for now, since it's likely some dumb error I'm making. I'll pursue some other areas of interest instead, and perhaps another forum reader might have this same problem and post a reply here or elsewhere. Whatever the case, I can wait for an answer. I'm very grateful for all your previous help though.
#5
08/29/2001 (8:25 pm)
I think I might know what is going on.

Datablocks can NOT be defined before the server starts because when it does start it clears out all the old information and reloads it.

What you will need to do is attach to the create server function and execute your scripts there:

Below is the code I used in the main.cs of my weapon example.

package weaponload
{

function createServer(%serverType, %mission)
{
   parent::createServer(%serverType, %mission);

   exec("~/scripts/item.cs");
   exec("~/scripts/inventory.cs");
   exec("~/scripts/weapons.cs");
   exec("~/scripts/weapon.cs");
}

};
activatepackage(weaponload);

What this does is basicly appends the execute commands for the scripts in my weapon example to the end of the createServer function.

The Alternative is editing the createServer function in the /server/scripts/server.cs file and adding those functions there.
#6
08/29/2001 (8:32 pm)
It does have to be run after the createServer is executed. I usually add new server exec's directly in the createServer function, though in the latest code I've broken out the execs into a new server init function. Anyway, this is most likely the problem. Thanks LabRat :)
#7
08/29/2001 (8:40 pm)
I was thinking of a system much like the MessageCallback for adding things to the init function.

ie. in the main.cs of your "module" you could add:

addInitScript("weapons/scripts/weapons.cs");
addInitScript("weapons/scripts/inventory.cs");
addInitScript("weapons/scripts/item.cs");

and

addInitFunction("name","arg1","arg2","argx");


With scripts being called first then functions. Or with a more detailed function you could add a grouping variable:

addInitScript(,