Understanding datablocks?
by David Schwanke · in Torque Game Engine · 06/19/2004 (2:04 pm) · 12 replies
Ok. Im digging into my basic understanding of datablocks again. To note, I just read about a guy that quote after four months of playing around with torque, still didnt understand them, so I dont feel so bad not knowing what I'm doing. :D
I have:
A C++ class RpgItem .. that lets me have ..
datablock RpgItemData .. and create ..
datablock RpgItem(GenericBackpack) .. from that RpgItemData.
The GenericBackpack is designed with a SimGroup inside of it to contain other items.
I want to create a GenericBackpack right after the %player creation in game.cs and assign it to the field %player.backpack.
Thing is, I cant seem to figure out how to create a GenericBackpack.
I think my problem is I am used to working in C++ where you have classes and instances of classes. I thought since you created all of your instances via new and since datablock was like a class definition of specialzied type. That you should be able to do
new GenericBackpack();
However, when I do that in game it gives me:
Couldnt find class rep for dynamics class:.
I thought hmm, ok, so maybe then datablock is actually creating a specialzied instance.
So when I backed up the tree a little bit and made it
new RpgItemData(GenericBackpack);
it works, but it doesnt retain any of the specialized data from the otherwise defined GenericBackpack AND when I try to insert a GenericBackpack via the game editor. It crashes the editor. (presumably because it has the same name as the created object).
So my question is simply.
How do I create an object into the game via script (that does not get placed in the game visually) that is based off of the sub class of my RpgItem that is off of GenericBackpack?
There has got to be a way to create items via scripts the same way that the editor creates them. But I havnt the first clue how to figure out the editor in terms of disecting the script.
And for the record. Yes ive done my homework. Ive reread severanl documents on datablocks but they all seemed to be more basic information then this. Which doesnt make sense cuz this seems pretty basic to me.
I have:
A C++ class RpgItem .. that lets me have ..
datablock RpgItemData .. and create ..
datablock RpgItem(GenericBackpack) .. from that RpgItemData.
The GenericBackpack is designed with a SimGroup inside of it to contain other items.
I want to create a GenericBackpack right after the %player creation in game.cs and assign it to the field %player.backpack.
Thing is, I cant seem to figure out how to create a GenericBackpack.
I think my problem is I am used to working in C++ where you have classes and instances of classes. I thought since you created all of your instances via new
new GenericBackpack();
However, when I do that in game it gives me:
Couldnt find class rep for dynamics class:.
I thought hmm, ok, so maybe then datablock is actually creating a specialzied instance.
So when I backed up the tree a little bit and made it
new RpgItemData(GenericBackpack);
it works, but it doesnt retain any of the specialized data from the otherwise defined GenericBackpack AND when I try to insert a GenericBackpack via the game editor. It crashes the editor. (presumably because it has the same name as the created object).
So my question is simply.
How do I create an object into the game via script (that does not get placed in the game visually) that is based off of the sub class of my RpgItem that is off of GenericBackpack?
There has got to be a way to create items via scripts the same way that the editor creates them. But I havnt the first clue how to figure out the editor in terms of disecting the script.
And for the record. Yes ive done my homework. Ive reread severanl documents on datablocks but they all seemed to be more basic information then this. Which doesnt make sense cuz this seems pretty basic to me.
#2
As my modified example from the 3d book I have but the datablock variables defined by GenericBackpack dont seem to be showing up when I do a .dump() on the backpack.
Specificially I have:
So what did I miss? :(
06/19/2004 (2:24 pm)
OK, I found the very simple:%player.backpack = new RpgItemData() {
datablock = GenericBackpack;
}As my modified example from the 3d book I have but the datablock variables defined by GenericBackpack dont seem to be showing up when I do a .dump() on the backpack.
Specificially I have:
datablock RpgItemData(GenericBackpack)
{
// Mission editor category
category = "TestItem";
// Basic Item properties
// Too lazy to make a generic item dts.
shapeFile = "~/data/shapes/items/healthKit.dts";
baseName = "Generic Backpack";
shortDesc = "This is a Generic Backpack Item.";
longDesc = "This is a Generic Backpack Item that schwanke created to test generic backpacks.";
baseWeight = "0"; // Dont count for anything.
// Gets moved to item creation?
// Nope. Stays here.
decayStatus = "-1"; // Does not decay.
owner = "Schwanke";
creator = "Schwanke";
mass = 1;
elasticity = 0.2;
friction = 0.6;
emap = true;
// Dynamic properties defined by the scripts
pickUpName = "a backpack";
image = HealthKitImage;
isContainer = true;
};So what did I miss? :(
#3
I thought the point of datablocks was to set the default settings to something specific to that datablock?
06/19/2004 (2:35 pm)
Ohh and the dump has the datablock set to GenericBackpack but I dont understand why the member fields didnt get set to the datablock fields. Did this 'work' and I just cant tell because I am expecting somethign to happen that doesnt happen?I thought the point of datablocks was to set the default settings to something specific to that datablock?
#4
06/19/2004 (3:56 pm)
If I remember right, member fields don't show up from the dump... only methods. Try making a custom method for your genericBackpack... (maybe unzip) and see if that shows up in the dump. I've actually never checked that myself. The member fields should be working just fine, though. Just give 'em a try.
#5
Dump shows me the fields. I have as the code:
And the output is :
... No compile error messages that i can find ...
DUMPING
basename:Generic Item
Member Fields:
... a bunch that i dont care about right now ...
baseName ' "Generic Item"
.... etc ....
So you can see, its creating the item and its dumping the fields and i can even access the fields via variables. But its not using the datablock information.
Actually i just dumped one of the items that I create via the mission editor and its a litle screwy. Some of the fields dont show up and other show up incorrectly.
So maybe I botched something in the class definition in C++. :( This is going to suck to debug. :( If your saying that my datablock defition is correct then I am going to trust that and look elsewhere for the problem.
And I was so happy that I was getting that item in game. :(
Thanks.
06/19/2004 (4:57 pm)
No. They arent. :(Dump shows me the fields. I have as the code:
%player.backpack = new RpgItemData(){
datablock = GenericBackpack;
};
error("DUMPING");
error("basename:" @ %player.backpack.basename);
%player.backpack.dump();And the output is :
... No compile error messages that i can find ...
DUMPING
basename:Generic Item
Member Fields:
... a bunch that i dont care about right now ...
baseName ' "Generic Item"
.... etc ....
So you can see, its creating the item and its dumping the fields and i can even access the fields via variables. But its not using the datablock information.
Actually i just dumped one of the items that I create via the mission editor and its a litle screwy. Some of the fields dont show up and other show up incorrectly.
So maybe I botched something in the class definition in C++. :( This is going to suck to debug. :( If your saying that my datablock defition is correct then I am going to trust that and look elsewhere for the problem.
And I was so happy that I was getting that item in game. :(
Thanks.
#6
Thanks for atleast confirming how to create a basic datablock.
06/19/2004 (5:27 pm)
Just found this resource: Basic SCriptable SimObject and noticed that my object is missing a few 'basics' so it looks like I botched it on the inside.Thanks for atleast confirming how to create a basic datablock.
#7
If not, post the C++ code so we can check it out.
06/19/2004 (10:44 pm)
David, let us know if it works once you make the changes you think you need to.If not, post the C++ code so we can check it out.
#8
i now have the RpgItem class skeletal structure that allows me to create RpgItemData datablock based RpgItems both in script and via the mission editor.
I can edit both via the console so the scripting is working.
I can also via initPersistFields I can change a variable in the object and have it printed back from the C++ code.
Success case if you ask me. Whee!
It actually works!
Maybe after I get further i will turn this into a resource for someone else. I dont know that I have all the basics installed yet since it dosnt actually do anything but store its own data.
06/20/2004 (2:47 pm)
Ok, basically I merged the tutorial with what I already had from extending the Item class and minimized the amount of code I was trying to test at once adding stuff back in as it went.i now have the RpgItem class skeletal structure that allows me to create RpgItemData datablock based RpgItems both in script and via the mission editor.
I can edit both via the console so the scripting is working.
I can also via initPersistFields I can change a variable in the object and have it printed back from the C++ code.
Success case if you ask me. Whee!
It actually works!
Maybe after I get further i will turn this into a resource for someone else. I dont know that I have all the basics installed yet since it dosnt actually do anything but store its own data.
#9
06/20/2004 (2:48 pm)
Next is to go back to the simsets stuff to see if i can make this a container item.
#10
06/22/2004 (10:30 am)
Cool, let us know how it goes :)
#11
Now I can use the mission editor to place an RpgItem based item.
I can pickup the object via running it over and it gets added to my 'backpack'.
I can press I to list the inventory of my backpack. (in text).
I'm waiting for someone else on our team to finish with their gui learning so I can base the gui interface off it. Save a little on the work and have a higher chance of intergrated visuals.
Thanks you all for the help.
06/22/2004 (10:36 am)
Its working :DNow I can use the mission editor to place an RpgItem based item.
I can pickup the object via running it over and it gets added to my 'backpack'.
I can press I to list the inventory of my backpack. (in text).
I'm waiting for someone else on our team to finish with their gui learning so I can base the gui interface off it. Save a little on the work and have a higher chance of intergrated visuals.
Thanks you all for the help.
#12
06/24/2004 (3:09 pm)
Hey rockin David. Good job!
Torque Owner David Schwanke
datablock RpgItem(GenericBackpack) called? I'm sure if I knew that I could probably search better on it.