what is the work of this codes of inventory.cs?
by Ahsan Muzaheed · in Torque 3D Beginner · 07/21/2011 (8:00 am) · 1 replies
function ShapeBase::setInventory
of
inventory.cs contains this codes:
cannot understand the purpose of this part:
and
what is inv[%name] and where it located?
of
inventory.cs contains this codes:
function ShapeBase::setInventory(%this, %data, %value)
{
if (%value < 0)
%value = 0;
else
{
%max = %this.maxInventory(%data);
if (%value > %max)
%value = %max;
}
// 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);
}
return %value;
}cannot understand the purpose of this part:
%name = %data.getName();
if (%this.inv[%name] != %value)
{
%this.inv[%name] = %value;
%data.onInventory(%this, %value);
%this.getDataBlock().onInventory(%data, %value);
}and
what is inv[%name] and where it located?
About the author
Torque 3D enthusiastic since 2010.Have been working in several T3D projects besides of Unreal Engine 4 and Unity 3D. NEED a hand with your project? SHoot me a mail. http://www.garagegames.com/community/forums /viewthread/138437/
Community Manager Michael Perry
ZombieShortbus
If I were to add comments to the code, it would look like this:
// Get the name of ItemData datablock %name = %data.getName(); // If the object's inventory (at %name index) does not // match the value if (%this.inv[%name] != %value) { // Set the new value of that inventory slot %this.inv[%name] = %value; // Execute the onInventory callback for the ItemData %data.onInventory(%this, %value); // Execute the onInventory callback for the ShapeBase // This is most likely the PlayerData %this.getDataBlock().onInventory(%data, %value); }