Making a copy of datablocks...
by Marco Bancale · in Torque Game Engine · 12/28/2002 (7:11 am) · 4 replies
First of all... hi to everyone
I've got a problem. I'm developing a Inventory script for my game. It is different from the basic inventory... It must mantain some of the characteristics of the object, such as how may charges are left in a magic wand. To do this I must copy the datablock of an object to my inventory (basically an array) before remove the object from the world.
I think that
%this.inv[%i]=%object.getDataBlock();
will copy only the reference of the datablocks.
so, (i think again) when i call a
%object.delete();
the datablock will be destroyed with the object.
after all... the question is:
How can I do a copy of the datablock instead of copying the reference?
thanks in advice...
F104
I've got a problem. I'm developing a Inventory script for my game. It is different from the basic inventory... It must mantain some of the characteristics of the object, such as how may charges are left in a magic wand. To do this I must copy the datablock of an object to my inventory (basically an array) before remove the object from the world.
I think that
%this.inv[%i]=%object.getDataBlock();
will copy only the reference of the datablocks.
so, (i think again) when i call a
%object.delete();
the datablock will be destroyed with the object.
after all... the question is:
How can I do a copy of the datablock instead of copying the reference?
thanks in advice...
F104
About the author
#2
I know how to store an inventory on the player object...
but I think that datablocks are static informations... did you mean that? changing a data in a datablock will result in a change in all similar datablocks... is it right? So I must store informations that can be changed dynamically in a variable attached to the object itself, not to his datablock... with a ScriptObject for example...
thanks...
12/29/2002 (2:28 am)
Mhh... the problem is not the player object but the object itself...I know how to store an inventory on the player object...
but I think that datablocks are static informations... did you mean that? changing a data in a datablock will result in a change in all similar datablocks... is it right? So I must store informations that can be changed dynamically in a variable attached to the object itself, not to his datablock... with a ScriptObject for example...
thanks...
#3
The minute an object is picked up it no longer exists in the world and all variables and objects attached to it are deleted.
What you have to do is pass the information to the player object when the item is picked up and then pass the information back to the object when it is dropped / sold / whatever.
If you're doing a MMORPG the data passed could be as simple as the ID of the object stored in the database. For a FPS it would be a simple variable to represent damage level, charges on a want, rounds of ammo in a clip.
For example in the ItemData::onPickup function you would something like:
%user.charges[%this.getName()] = %obj.charges;
And when you throw the item (ItemData::onThrow):
%obj = new Item() {
datablock = %this;
rotation = "0 0 1 " @ (getRandom() * 360);
charges= %user.charges[%this.getName()];
};
MissionGroup.add(%obj);
A ScriptObject based inventory control system would work also, more so for a MMORPG type inventory system that can survive death. In that case you would attach the information to the client object as information attached to the player object gets deleted when you die.
I had implemented some of this, in a Tribes 1 MOD that was never released, in the form of damage to weapons and other carried items. Damage levels affected the misfire rate of weapons and had to follow the weapons when they were dropped and picked up.
12/29/2002 (3:53 am)
You can not attach information to an object if you want it to be persistant.The minute an object is picked up it no longer exists in the world and all variables and objects attached to it are deleted.
What you have to do is pass the information to the player object when the item is picked up and then pass the information back to the object when it is dropped / sold / whatever.
If you're doing a MMORPG the data passed could be as simple as the ID of the object stored in the database. For a FPS it would be a simple variable to represent damage level, charges on a want, rounds of ammo in a clip.
For example in the ItemData::onPickup function you would something like:
%user.charges[%this.getName()] = %obj.charges;
And when you throw the item (ItemData::onThrow):
%obj = new Item() {
datablock = %this;
rotation = "0 0 1 " @ (getRandom() * 360);
charges= %user.charges[%this.getName()];
};
MissionGroup.add(%obj);
A ScriptObject based inventory control system would work also, more so for a MMORPG type inventory system that can survive death. In that case you would attach the information to the client object as information attached to the player object gets deleted when you die.
I had implemented some of this, in a Tribes 1 MOD that was never released, in the form of damage to weapons and other carried items. Damage levels affected the misfire rate of weapons and had to follow the weapons when they were dropped and picked up.
#4
This way:
I've built up an inventory system with a script object attached to the player object. Script object holds Inventory in an array of script objects... (explain below) and have metods to add, remove etc etc...
Each pickupable object in the game have a script object that I create in the create method, like this
function ItemData::create(%data)
{
%dt = new ScriptObject(){
class = ItemDynamicData;
};
%obj = new Item() {
dataBlock = %data;
static = false;
rotate = false;
dyData = %dt;
};
return %obj;
}
So each different object can have different persistent data stored in dyData. each time player pickUp an object I store the dyData (and the type of datablock) in the Inventory. So I can track dynamic data.
I'm working on a different kind of inventory. I can write a small tut at the end if someone think that this can be useful...
01/03/2003 (11:35 pm)
Ok... really thanks. I've done that.This way:
I've built up an inventory system with a script object attached to the player object. Script object holds Inventory in an array of script objects... (explain below) and have metods to add, remove etc etc...
Each pickupable object in the game have a script object that I create in the create method, like this
function ItemData::create(%data)
{
%dt = new ScriptObject(){
class = ItemDynamicData;
};
%obj = new Item() {
dataBlock = %data;
static = false;
rotate = false;
dyData = %dt;
};
return %obj;
}
So each different object can have different persistent data stored in dyData. each time player pickUp an object I store the dyData (and the type of datablock) in the Inventory. So I can track dynamic data.
I'm working on a different kind of inventory. I can write a small tut at the end if someone think that this can be useful...
Torque Owner Harold "LabRat" Brown