Game Development Community

Shapebase::Pickup Question

by Dustin Sims · in Torque Game Engine · 06/24/2008 (3:51 pm) · 4 replies

Does anyone know where Shapebase::Pickup gets the %amount variable from?

It's setup like this , Shapebase::Pickup(%this, %data, %amount).
%amount is always null.
It uses that to determine whether or not to inc inventory on down the line.
I cannot find any information on what calls the Pickup function either to determine
where the %amount would come from.

I am basically just trying to get the default inventory system woeking like it was intended(I think).
Seems a little cumbersome. I can get it to work like I want if I set a breakpoint in Torsion and modify %amount to = 1 and then let it continue.

#1
06/24/2008 (4:10 pm)
Looking at the script (in starter.fps), I don't think anything ever gets passed into it. It's all taken care of with two lines of code:
if (%amount $= "")
      %amount = %this.maxInventory(%data) - %this.getInventory(%data);
#2
06/25/2008 (7:40 am)
Dustin -

It's called in server/scripts/player.cs... do a search for "%obj.pickup(%col);"

You are quite correct as you see above it never passes in an amount, just the object it collided with. As this function is called when colliding with a single object you could only ever get 1, it leaves you two choices:

a) Either hardcode the amount to be 1 (Yuck!!)

or

b) Edit the datablock to add an inventory_amount = 5 (for example) for each item you want to pick up more than 1 of and change the Shapebase::pickup() function to look like:

function ShapeBase::pickup(%this,%obj)
{
   // This method is called to pickup an object and add it
   // to the inventory. The datablock onPickup method is actually
   // responsible for doing all the work, including incrementing
   // the inventory.
   %data = %obj.getDatablock();

    if (%data.inventory_amount $= "")
        %amount = %data.inventory_amount;
    else
        %amount = 1;

   // Try and pickup the max if no value was specified
   if (%amount $= "")
      %amount = %this.maxInventory(%data) - %this.getInventory(%data);

   // The datablock does the work...
   if (%amount < 0)
      %amount = 0;
   if (%amount)
      return %data.onPickup(%obj,%this,%amount);
   return false;
}

That way if you set an inventory amount in the datablock it's used, if not it just defaults to 1.
#3
06/25/2008 (2:17 pm)
Nathan-
The only problem with that calculating the amount was that it would come back with the max amount that could be inventoried and add that.

Andy-
Excellent. That was what I was looking for. I just couldn't seem to figure out what was calling the pickup function. This will get me headed in the right direction.
Thanks.
#4
06/25/2008 (4:19 pm)
Np Dustin.. hope it works out for ya