Game Development Community

Problem with registering class

by Koushik · in Torque Game Engine · 01/19/2008 (5:18 am) · 8 replies

Ok, I'm kinda new to the engine code, so this is experimental....

I was trying to expose a new class to the console. I've basically derived from the vehicle class and have implemented animation functions similar to the ones in the player class.

When I call the new() method on the console to create an instance of the class, the engine simply crashes... I'm using the racing MOD as a basis for my script, and when I execute my script file, it compiles OK (which, I suppose, means that my datablock is being recognized and instantiated). Its when I call the new() method in the game.cs script, just before/after instantiating a car object as the controlling object in the createRace() function.

I'd be happy if somebody could tell me what needs to be taken care of when initializing custom objects in script. Are there methods that have to be implemented without fail, which would otherwise cause a crash? Any thing specifically for objects deriving from the vehicle class?

I'm assuming there's no problem with my class code, because a) the code compiled without any warnings at all and b) I've been pouring over the engine documentation till my eyes turned sore.

Thanks a ton!

#1
01/19/2008 (6:00 am)
Quote:
I'm assuming there's no problem with my class code, because a) the code compiled without any warnings at all and b) I've been pouring over the engine documentation till my eyes turned sore.

ROFL -- Thats the biggest laugh I've had all year!


--- My girl just got home, I'll come back and be helpful later :)
#2
01/19/2008 (6:22 am)
Once you have created a custom class and exposed it correctly to script, you then treat it the same as any other existing classes. Derived classes do not require any special treatment.

Here are a few TDN articles that may help you:
tdn.garagegames.com/wiki/Torque_Game_Engine#coder
tdn.garagegames.com/wiki/Code/How_do_I_make_a_scriptable_object%3F
tdn.garagegames.com/wiki/Code/How_do_I_make_an_object_with_a_datablock%3F

There are several things that may be causing it to crash Torque. What errors are you getting? Are you creating a custom Datablock for your new class too?

If you want to post your code here, I can have a look over it and possibly point out any problems.

Gabriel
#3
01/19/2008 (7:09 pm)
Thanks for that gabriel...

I am using a custom datablock, which derives from the vehicleData class. The code is...well.. kinda similar to teh player class, only it derives from vehicle instead of shapebase. I based my code on the player.cc and payer.h files.

I was toying around a bit today, and I got a couple of things out... Firstly, if I don't specify a datablock while instantiating my object, it doesn't crash, but in the console.log file, I get:

test/server/scripts/game.cs (318): Register object failed for object (null) of class Test.
test/server/scripts/game.cs (322): Unable to find object: '0' attempting to call function 'setTransform'
test/server/scripts/game.cs (323): Unable to find object: '0' attempting to call function 'setShapeName'

If I uncomment the line specifying the datablock, the engine just crashes.

So now I'm assuming there's a problem with my datablock, though my test.cs file (the one initializing the datablock) doesn't show any compilation error at all.

In case you want to check my code, cowness.forever.googlepages.com/code.rar
(I've changed the name of the class in the rar file)

EDIT: I've gotten the datablock to load properly, I didn't give a name for the class object. Now it says this:

Object 'testData' is not a member of the 'GameBaseData' data block class
test/server/scripts/game.cs (317): Register object failed for object (null) of class Test.

EDIT2: Nevermind the previous EDIT, made a real bummer... I'm back where I was... torque still crashing when specifying the datablock, but the datablock.dump() method returns all the initialized variables...

So yeah, I'm just as clueless as before...
#4
01/20/2008 (5:59 am)
Please post the script and datablock you are using to create the object as well. I forget why I usually get this error but it is something really easy.
#5
01/20/2008 (6:33 am)
cowness.forever.googlepages.com/scripts.rar

Here you go... its practically a rewrite of the player class with some changes.. I've included my game.cs script as well, just in case... It just crashes when it encounters the new() command
#6
01/20/2008 (3:33 pm)
I think I have found the possible source of the problem.

I ran it in Visual Studio and it crashed on the following line (line 552 in vehicle.cc):
AssertFatal(mDataBlock->collisionDetails[0] != -1, "Error, a vehicle must have a collision-1 detail!");

It seems that vehicle based objects have different collision mesh requirements to that of the player shapes.

Something on vehicles:

http://tdn.garagegames.com/wiki/DTS/3dsmax/Creating_a_Simple_Wheeled_Vehicle#Ve...


Gabriel
#7
01/21/2008 (4:56 am)
Actually that may not be the problem at all seeing as I was probably using a different shape object.

Gabriel
#8
01/21/2008 (7:43 am)
I think that might as have been the problem.. I removed the collision methods in my source files (I stuck with the methods that were derived automatically from the vehicle class)...

well, the crashes stopped, but when I made my class the controllable object, it simply refuses to move...

I've tried it with a different shape as well (the stock vehicle that comes with torque) and it still doesn't move...

So yeah, from one problem to another...

EDIT: Gabriel, did you get the previous code to work? What shape did you use? Any changes?