Changing the shapefile of a datablock in game.
by Jeff Trier · in Torque Game Engine · 05/05/2003 (6:32 am) · 10 replies
I am able to have a bot load in with a weapon, but I was wondering if I could have that weapons shapefile change on the fly while still keeping all the old weapon data. Basically just have it morph...
I can't seem to get it.
Thanks,
-Jeff
I can't seem to get it.
Thanks,
-Jeff
About the author
Originally a Classical/Metal musician, I've always been attracted to anything involving computers, including: Networking, PC Building and Repair, software design and coding. I've been involved with game design and development for over 10 years.
#2
In the game I am creating, the player will create objects in a "Lab" pre-game, as well as units that will use those objects. So they could create a gun and select the type of gun it is (Pistol, Rifle, etc...), then select various attributes for that gun (sights, scopes, etc...).
When I go into the game, I can spawn the units I created with this method with exception of the weapon thus far. What I am looking for is a way to spawn a pistol model if the defined unit has a pistol, a rifle if the defined unit has a rifle, etc...
I know I could create datablocks for each possible combination of gun, but that would be an amazing amount of Datablocks. I figured I could make a generic gun class, and have all of its sub definitions (image, effects, etc...) defined based on the user definements.
If I am off-base, would you mind steering me in the right direction?
Thanks,
-Jeff
05/05/2003 (2:09 pm)
Hmm, I created skills for a player by using variables that change within an object that was created with a datablock... Will this cause problems? It seems to work so far, but I haven't tested it in a multiplayer environment yet. I figured that since this seemed to work, I could change the shapefile in the same manner.In the game I am creating, the player will create objects in a "Lab" pre-game, as well as units that will use those objects. So they could create a gun and select the type of gun it is (Pistol, Rifle, etc...), then select various attributes for that gun (sights, scopes, etc...).
When I go into the game, I can spawn the units I created with this method with exception of the weapon thus far. What I am looking for is a way to spawn a pistol model if the defined unit has a pistol, a rifle if the defined unit has a rifle, etc...
I know I could create datablocks for each possible combination of gun, but that would be an amazing amount of Datablocks. I figured I could make a generic gun class, and have all of its sub definitions (image, effects, etc...) defined based on the user definements.
If I am off-base, would you mind steering me in the right direction?
Thanks,
-Jeff
#3
Datablocks are supposed to be "static" information about the class of objects, not to hold instance specfic information.
05/05/2003 (2:32 pm)
@Jeff - Datablock objects are GLOBAL for all instances of that object, which means if you have an attribute on a datablock it affects every instance of that particular object. There is a mechanism for changing datablock values, but it changes the value for ALL the objects of that class.Datablocks are supposed to be "static" information about the class of objects, not to hold instance specfic information.
#4
How would you recommend I create skills and dynamic variances for an object?
EDIT:
I was doing some more poking around and came across inheritance. Would that be something to persue?
It seems to copy the attributes from a parent object, but I am wondering if that is something I should/could use for objects that can change variables and appearance in game.
Thanks again,
-Jeff
05/05/2003 (3:50 pm)
Doh! Thanks, that's definatly something to think about.How would you recommend I create skills and dynamic variances for an object?
EDIT:
I was doing some more poking around and came across inheritance. Would that be something to persue?
datablock ClassName(DatablockName : ParentDatablockName){
....
};It seems to copy the attributes from a parent object, but I am wondering if that is something I should/could use for objects that can change variables and appearance in game.
Thanks again,
-Jeff
#5
05/05/2003 (4:04 pm)
Even though you can't change the value of a datablock on the fly you can still change what datablock an object uses on the fly. My recommendation would be to create multiple datablocks, and then switch which datablock the object uses when you need to.
#6
I think I can manage with that. I may have to make multi-part objects to achieve the effect I want. A bit more coding, but if that's what it takes. ;)
-Jeff
05/05/2003 (4:15 pm)
Thanks Robert!I think I can manage with that. I may have to make multi-part objects to achieve the effect I want. A bit more coding, but if that's what it takes. ;)
-Jeff
#7
Actually the ONLY WAY was is to create instance variables, copy the datablocks into them and then manipulate the local instance variables in C++, or you can make them Script level variables, but I never really got anywhere with that.
Either way just switching out datablocks is not going to get you anything since they are still global in nature.
Imagine that datablocks are passed "by reference" and you have the idea, to have object customization you HAVE to have some kind of "by value" system where each object keeps up with itself.
This was a big stumbling block for me in the beginning also. The datablocks are like initializers, anything dynamic has to be local to the instance.
05/05/2003 (4:53 pm)
Quote:How would you recommend I create skills and dynamic variances for an object?
Actually the ONLY WAY was is to create instance variables, copy the datablocks into them and then manipulate the local instance variables in C++, or you can make them Script level variables, but I never really got anywhere with that.
Either way just switching out datablocks is not going to get you anything since they are still global in nature.
Imagine that datablocks are passed "by reference" and you have the idea, to have object customization you HAVE to have some kind of "by value" system where each object keeps up with itself.
This was a big stumbling block for me in the beginning also. The datablocks are like initializers, anything dynamic has to be local to the instance.
#8
05/05/2003 (5:05 pm)
I would look into ScriptObjects, and use the save() method of them for implementing skills (just a thought)
#9
Thanks again,
-Jeff
05/05/2003 (5:08 pm)
Right, I get what you are saying. This is a bit of a stumbling block for my game design. I guess I am going to try the c++ route.Thanks again,
-Jeff
#10
I have all the info saved on files already, though... Hmmm... I guess I can load the info into an array for each unit and reference those. :)
I think that just might work, though I wonder how slow it might get during combat.
Thanks for the idea. :)
-Jeff
05/05/2003 (5:14 pm)
@BryanI have all the info saved on files already, though... Hmmm... I guess I can load the info into an array for each unit and reference those. :)
I think that just might work, though I wonder how slow it might get during combat.
Thanks for the idea. :)
-Jeff
Torque Owner Josh Albrecht
To accomplish what you want to do, you should create a function to unload the current weapon, and transfer the relevant data to the next weapon that you mount.