Item onCollision strangeness
by Lee Latham · in Torque Game Engine · 04/03/2008 (8:18 am) · 5 replies
This seems to be my week for bizarre problems!
I have a simple weapon Item. The problem is, it ignores one of my conditionals and a return statement!
The second "if" statement works fine--if a vehicle collides with the item, it gives the player the message and the item isn't picked up. But the first one--it's honored, in that if the client is a flag carrier, it sends the message to the client--BUT, then it continues on to mount the shotgun and add it to the inventory, and the item disappears from the game for a bit.
I've stared at this until my eyes are bleeding, and I don't have any bizarre messages in the console. Any ideas?
And, if that wasn't weird enough, I tried combining the two conditionals:
And guess what...SAME results. When I drive through with a car I get the message and the item isn't picked up. But if I walk though it with the flag I get the message, AND the item is picked up.
ROFL maniacally.
I have a simple weapon Item. The problem is, it ignores one of my conditionals and a return statement!
function ShotgunItem::onCollision(%this,%obj,%col)
{
if (%col.client.carrier){
messageClient(%col.client, '', '\c2You have the enemy flag. What do you need a weapon for?');
return;
}
if (%col.getClassName() !$= "Player") {
messageClient(%col.client, '', '\c2Only players can use this item! (get out of your vehicle to get it if you want)');
return;
}
%col.mountImage(ShotgunImage,0,true);
%col.setInventory(ShotgunItem,1);
}The second "if" statement works fine--if a vehicle collides with the item, it gives the player the message and the item isn't picked up. But the first one--it's honored, in that if the client is a flag carrier, it sends the message to the client--BUT, then it continues on to mount the shotgun and add it to the inventory, and the item disappears from the game for a bit.
I've stared at this until my eyes are bleeding, and I don't have any bizarre messages in the console. Any ideas?
And, if that wasn't weird enough, I tried combining the two conditionals:
if (%col.client.carrier || %col.getClassName() !$= "Player"){
messageClient(%col.client, '', '\c2You have the enemy flag. What do you need a weapon for?');
return;And guess what...SAME results. When I drive through with a car I get the message and the item isn't picked up. But if I walk though it with the flag I get the message, AND the item is picked up.
ROFL maniacally.
#2
Yeah, I tried deleting the dso's, too. I would think the problem is source-side, but I can't think how that's possible.
04/03/2008 (9:46 am)
Thanks. I should have mentioned that I did do that, with strange results. It seemed to obey the return statement, but then went immediately the the servermessage command telling you that you've picked up a shotgun.Yeah, I tried deleting the dso's, too. I would think the problem is source-side, but I can't think how that's possible.
#3
I went back in and instead of relying on Torsion, I turned trace on right before colliding with the item, and here is what I got:
So it appears that it is going straight from the player colliding with the item to Shapebase::pickup...oh yeah! I was just today noticing that in the Armor::onCollision code, kinda incidentally. That must be it! It says right there at the top:
That's gotta be it. Hmm it would be cool if Torsion could let you know "hey, there's some other stuff happening", somehow. Although I guess that could be quite tricky to show.
Thanks for your input, Eric!
04/03/2008 (10:04 am)
Ok, this is interesting. I should mention that I'm only now using the built-in inventory system, and it seems to have some mysteries for me, still. I'm thinking that perhaps there is an automated aspect to it? I went back in and instead of relying on Torsion, I turned trace on right before colliding with the item, and here is what I got:
Entering armor::onCollision(187, 8970, 8583)
Entering ShapeBase::pickup(8970, 8583)
Entering ShapeBase::getInventory(8970, 251)
Leaving ShapeBase::getInventory() - return
Entering ShapeBase::maxInventory(8970, 251)
Leaving ShapeBase::maxInventory() - return 1
Entering Weapon::onPickup(251, 8583, 8970, 1)
Entering ItemData::onPickup(251, 8583, 8970, 1)
Entering ShapeBase::incInventory(8970, 251, 1)
Entering ShapeBase::maxInventory(8970, 251)
Leaving ShapeBase::maxInventory() - return 1
Entering ShapeBase::setInventory(8970, 251, 1)
Entering ShapeBase::maxInventory(8970, 251)
Leaving ShapeBase::maxInventory() - return 1
Entering Weapon::onInventory(251, 8970, 1)
Leaving Weapon::onInventory() - return 1
Leaving ShapeBase::setInventory() - return 1
Leaving ShapeBase::incInventory() - return 1
Entering messageClient(8667, 76, 77, a nice semi-automatic shotgun. Have a nice day.)So it appears that it is going straight from the player colliding with the item to Shapebase::pickup...oh yeah! I was just today noticing that in the Armor::onCollision code, kinda incidentally. That must be it! It says right there at the top:
// Try and pickup all items
if (%col.getClassName() $= "Item")
%obj.pickup(%col);That's gotta be it. Hmm it would be cool if Torsion could let you know "hey, there's some other stuff happening", somehow. Although I guess that could be quite tricky to show.
Thanks for your input, Eric!
#4
I know I've made odd mistakes like that before when doing a lot of copy-paste code.
Doh, looks like you found it right before I posted.
04/03/2008 (10:07 am)
Is it possible that there may be a similar function, possibly even another copy, hiding somewhere that is making the call, maybe something on the player side?I know I've made odd mistakes like that before when doing a lot of copy-paste code.
Doh, looks like you found it right before I posted.
#5
04/03/2008 (12:01 pm)
Thanks, anyway! :-)
Torque 3D Owner Eric Armstrong
Bloody Tongue Games
I don't see anything obviously wrong with it, so not sure what is going on...