Game Development Community

Inventory.cs - Unknown command onUse

by Dennis Lamers · in Torque Game Engine · 06/04/2015 (12:13 pm) · 3 replies

Hey all,

I was testing a new map to let players pickup the weapons. Once it came to my attention that the weapons didn't switch, I checked the console and saw this. After doing some back-ups the problem still wasn't fixed, and after three hours of trying I decided to post the problem.
starter.fps/server/scripts/inventory.cs (51): Unknown command onUse.
  Object Crossbow(1851) Item -> ShapeBase -> GameBase -> SceneObject -> NetObject -> SimObject

I've googled to this problem, but it still didn't fix.

#1
06/04/2015 (2:00 pm)
Problem solved. Here is the solution to fix it:

When ever you place a weapon in the map, everyone is automatically naming the item. For example, we call the item Sniper. But the datablock is called sniper too, and so does the conflict start between the item and datablock name.
new Item(Sniper) {
            canSaveDynamicFields = "1";
            position = "211.631 -469.904 40.6473";
            rotation = "1 0 0 0";
            scale = "1 1 1";
            dataBlock = "Sniper";
            collidable = "0";
            static = "1";
            rotate = "1";
         };

So we call the item Sniper1.
new Item(Sniper1) {
            canSaveDynamicFields = "1";
            position = "211.631 -469.904 40.6473";
            rotation = "1 0 0 0";
            scale = "1 1 1";
            dataBlock = "Sniper";
            collidable = "0";
            static = "1";
            rotate = "1";
         };

This was an easy one, but very hard to find.
#2
06/04/2015 (3:32 pm)
It is common to name the datablock something like SniperWeaponData so that you won't have conflicts like that and it isn't required to name objects unless you are going to be scripting them and need an easy way to reference said objects.
#3
06/04/2015 (9:57 pm)
Yeah, like Nate says, you don't have to name the items unless you're writing script that applies specifically to that instance.

new Item(){  // create hundreds of Items using the Sniper datablock just like this.
  ...
  datablock = "Sniper";
  ...
};


new Item(TrappedRifle){ ... }; // shortened to save space

function TrappedRifle::onPickUp(%this)
{
    // do something for that particular rifle
}

datablock ItemData(SniperRifle){ ... };

function SniperRifle::onPickUp(%this)
{
    // do something for all items using the SniperRifle datablock
}
Hope that clarifies a little.