Simple ItemData question
by Nmuta Jones · in Torque Game Engine · 06/30/2009 (10:25 pm) · 13 replies
I have a coin that I want players to be able to pick up.
For now, I am treating it like ammo in the inventory system.
Since I am using the ItemData datablock, I *thought* that it would automatically inherit all of the functionality of the item.cs and inventory.cs files. But in the game, it does show up under ammo, and it places in game ok, and starts rotating like ammo, but I can't pick it up. What am I doing wrong? In coin.cs I simply put:
For now, I am treating it like ammo in the inventory system.
Since I am using the ItemData datablock, I *thought* that it would automatically inherit all of the functionality of the item.cs and inventory.cs files. But in the game, it does show up under ammo, and it places in game ok, and starts rotating like ammo, but I can't pick it up. What am I doing wrong? In coin.cs I simply put:
datablock ItemData(Coin)
{
// Mission editor category
category = "Ammo";
// Add the Ammo namespace as a parent. The ammo namespace provides
// common ammo related functions and hooks into the inventory system.
className = "Ammo";
// Basic Item properties
shapeFile = "~/data/shapes/coin/coin.dts";
silentBBoxValidation = true;
mass = 1;
elasticity = 0.2;
friction = 0.6;
// Dynamic properties defined by the scripts
pickUpName = "coin";
maxInventory = 20;
};About the author
Lead Developer for MediaBreeze Multimedia
#2
06/30/2009 (10:41 pm)
Ok, great, thanks..... that makes sense. It works now.
#3
How do I access that function from within another server side script? I have a gui I've implemented, and I'm still a little shaky on how to get to these functions that exist within namespaces.
I basically want to access my current coin inventory at various times through script.
06/30/2009 (10:45 pm)
Also, in inventory.cs I seefunction ShapeBase::getInventory(%this,%data)
{
// Return the current inventory amount
return %this.inv[%data.getName()];
}How do I access that function from within another server side script? I have a gui I've implemented, and I'm still a little shaky on how to get to these functions that exist within namespaces.
I basically want to access my current coin inventory at various times through script.
#4
I thought I was picking it up but I'm not. I had put in on onCollision handler and that alone was causing it to disappear because I had explicity called to delete the object in that handler.
My Coin object is, for some reason, NOT being added to the item class because it's not triggering any of the item class functions, like onPickup, etc. I know this because I've put echo functions in Item.cs and none of them are being called.
This is supposed to be a simple process....what am I doing wrong?
07/01/2009 (5:25 am)
Actually, no, it's not working now.I thought I was picking it up but I'm not. I had put in on onCollision handler and that alone was causing it to disappear because I had explicity called to delete the object in that handler.
My Coin object is, for some reason, NOT being added to the item class because it's not triggering any of the item class functions, like onPickup, etc. I know this because I've put echo functions in Item.cs and none of them are being called.
This is supposed to be a simple process....what am I doing wrong?
#5
"Warning: shape arcane.fx/data/shapes/coin/coin.dts collision detail 0 (Collision-2) bounds exceed that of shape."
I'm not sure how to fix that..... everything looks correct in the way I set up the collision mesh for .dts export
////////////
I'm wondering if it's something wrong with my .dts shape. Because adding other things, like ammo, and health kit, etc. works and they have almost exactly the same code.
I know the collisions on my coin DO work, because I am able to successfully invoke the onCollision handler for it, and when I add as a simple shape in the game (not ItemData) I get a collision.
07/01/2009 (5:33 am)
Does it have anything to do with this error?"Warning: shape arcane.fx/data/shapes/coin/coin.dts collision detail 0 (Collision-2) bounds exceed that of shape."
I'm not sure how to fix that..... everything looks correct in the way I set up the collision mesh for .dts export
////////////
I'm wondering if it's something wrong with my .dts shape. Because adding other things, like ammo, and health kit, etc. works and they have almost exactly the same code.
I know the collisions on my coin DO work, because I am able to successfully invoke the onCollision handler for it, and when I add as a simple shape in the game (not ItemData) I get a collision.
#6
Maybe get rid of the ammo class field in your datablock (unless you want to use it as ammo) it maybe causing some namespace interference. Furthermore I do believe that using a custom onCollision() for an item will over-ride the default item-class pick up handling.
I've never seen this before: "silentBBoxValidation " what does that do?
07/01/2009 (12:52 pm)
Hmm weird, it should work. Several shapes have those collision bounds warnings and yet they still work.Maybe get rid of the ammo class field in your datablock (unless you want to use it as ammo) it maybe causing some namespace interference. Furthermore I do believe that using a custom onCollision() for an item will over-ride the default item-class pick up handling.
I've never seen this before: "silentBBoxValidation " what does that do?
#7
Problem still persists.
(Also I commented out that "silentBBoxValidation" as well....no dice)
I'm not sure what that is. I think its something FaustLogic put in there, since this game is derived from AFX 1.5.2
07/01/2009 (1:07 pm)
Well, just for the sake of it, I commented out the ammo class field. And I took out the onCollision() handler, which was indeed overridding things. Problem still persists.
(Also I commented out that "silentBBoxValidation" as well....no dice)
I'm not sure what that is. I think its something FaustLogic put in there, since this game is derived from AFX 1.5.2
#8
Basically the problem is in this line within coin.cs....somehow I had changed it to
maxinventory = 100;
which caused it to pick up 100 "coins" at once after colliding with the first coin. and I had not realized when that part of the code changed...
that was the problem. in player.cs the maxInventory is 100 so it maxed out after the first coin was picked up.
07/01/2009 (3:02 pm)
Ok, I got some VERY good help from Rob Sandbach, who also peruses these forums.....Basically the problem is in this line within coin.cs....somehow I had changed it to
maxinventory = 100;
which caused it to pick up 100 "coins" at once after colliding with the first coin. and I had not realized when that part of the code changed...
that was the problem. in player.cs the maxInventory is 100 so it maxed out after the first coin was picked up.
#9
I just assumed you would have had the item limit already in mind -- but at least you got it.
07/01/2009 (3:12 pm)
Well duh, yeah that would prevent you from picking up anymore ;)I just assumed you would have had the item limit already in mind -- but at least you got it.
#10
07/01/2009 (3:13 pm)
Yeah, that's what you get when you stay up until 2 am racking your brain on a code issue..... you end up working with fewer brain cells. I don't know how that 20 got changed to 100.
#11
07/01/2009 (3:21 pm)
Fewer brain cells -- haha, yeah I know all about that one from too many jager blurred code-fests and serious lack of sleep. It's almost like beer goggles :D
#12
07/01/2009 (3:27 pm)
Im glad we got it Nmuta! And now you know the wonders of trace() and tree()!
#13
No but seriously, trace() and tree() are phenomenal. Great debugging tools. Thanks.
07/01/2009 (3:44 pm)
Yeah. If I had not gotten a second pair of eyes on this, and continued to lose sleep, I could have lost every trace() of patience which would have driven me up a tree(). No but seriously, trace() and tree() are phenomenal. Great debugging tools. Thanks.
Associate Michael Hall
Big Kid Games
ie: maxInv[Coin] = 20;
If you can't have it, then you can't pick it up ;)
EDIT: the maxInventory field in your ItemData datablock is how many it gives you on pickup.