Need help with Inventory...
by Ryan Edmar · in Technical Issues · 03/08/2007 (12:32 am) · 2 replies
Hi all!
I need a little help from those with more experiance with Torque than I. I've been trying to create a simple inventory list system to be used for saving and loading of player info. I traced the item path from pickup to onInventory and found the right location for my idea was in setInventory. So I added a the call in bold and passed the datablock name and the amount being set...
// Set the value and invoke object callbacks
%name = %data.getName();
if (%this.inv[%name] != %value)
{
%this.inv[%name] = %value;
%data.onInventory(%this,%value);
%this.getDataBlock().onInventory(%data,%value);
// inventory test function
recordInv(%data,%value);
}
return %value;
...to the function I created, whitch is where my problem lies.
Here is the function:
function recordInv(%data,%value)
{
if (!isObject(%data))
{
%item = new scriptObject(%data)
{
amount = %value;
};
echo("Adding Item " @ %data);
MissionCleanup.add(%item);
}
else
{
%data.amount = %value;
echo("Adding " @ %value @ " to " @ %data);
}
}
The function does do what I wanted, I'll give a breif discription for simplicity. First it asks if the object already exisits, if not then it creates a script object with the name of the datablock and adds the amount of the item. If the object exist then it just updates the amount. note: the echo's where there so I could see if it worked or not. Now, while I was patting myself on the back I realized that this will include all items passed to setInventory, both player and aiplayer. I want it to only record items picked up by the current client player.
I'm open to any suggestions, or if you have a better way of doing this I would love to hear it. I've done alot of searching for ways of saving info with torque and found none that did what I wanted. Being that I'm not very strong in c++ this seemed to be the easiest way to accomplish my goal. So, any help would be greatly appreciated. Thanks.
I need a little help from those with more experiance with Torque than I. I've been trying to create a simple inventory list system to be used for saving and loading of player info. I traced the item path from pickup to onInventory and found the right location for my idea was in setInventory. So I added a the call in bold and passed the datablock name and the amount being set...
// Set the value and invoke object callbacks
%name = %data.getName();
if (%this.inv[%name] != %value)
{
%this.inv[%name] = %value;
%data.onInventory(%this,%value);
%this.getDataBlock().onInventory(%data,%value);
// inventory test function
recordInv(%data,%value);
}
return %value;
...to the function I created, whitch is where my problem lies.
Here is the function:
function recordInv(%data,%value)
{
if (!isObject(%data))
{
%item = new scriptObject(%data)
{
amount = %value;
};
echo("Adding Item " @ %data);
MissionCleanup.add(%item);
}
else
{
%data.amount = %value;
echo("Adding " @ %value @ " to " @ %data);
}
}
The function does do what I wanted, I'll give a breif discription for simplicity. First it asks if the object already exisits, if not then it creates a script object with the name of the datablock and adds the amount of the item. If the object exist then it just updates the amount. note: the echo's where there so I could see if it worked or not. Now, while I was patting myself on the back I realized that this will include all items passed to setInventory, both player and aiplayer. I want it to only record items picked up by the current client player.
I'm open to any suggestions, or if you have a better way of doing this I would love to hear it. I've done alot of searching for ways of saving info with torque and found none that did what I wanted. Being that I'm not very strong in c++ this seemed to be the easiest way to accomplish my goal. So, any help would be greatly appreciated. Thanks.
About the author
#2
03/09/2007 (12:12 am)
Thanks for the tip Martin it will help. I've seen that before but did not recall it at the time. That should work but I had to rewrite my function because it was not working like I thought. Because the datablock passed did already exist torque was just bypassing the first part of the if statement. This is just the beginning of what I'm working on so I will have plenty of time to work all the bugs out. Thanks again for you help.
Torque Owner Martin Schultz