Game Development Community

Crash? Please help.

by Matt "Mr. Pig" Razza · in Torque Game Engine · 12/18/2005 (12:33 pm) · 4 replies

Problem: When ever I throw a nade in the game I am currently developing the game crashes (when I only have the nade in inventory - no other weapons).

Detail:
This nade has been working for a while. I recently added a call to my removeWeapon function in my inventory system when the nade is thrown so that it would be unmounted and removed from inventory. After it is unmounted the inventory system would then scan for the next weapon the player is holding (looks through weapon slots - Knife is 1, Pistol is 2, Rifle is 3, Nade is 4, ect). If it finds a match it mounts the weapon and exits the loop. It then distroys the inventoryData for the Nade. Or it should...

I compiled the debug version of TGE 1.4 but I didn't see any difference running with that exe or anyother console data. (I don't know if there is any special command to run debug mode in that app). This is what happens - from my investigation into the script. You press fire, one nade is removed from inventort (0 are left). The fire function calls to removed the nade from inventory. It runs the removeWeapon function in my inventory system which checks if the weapon being removed is mounted (which it is). It then unmounts the weapon image and searchs for a new weapon to mount - if one is found, it mounts it and works correctly. If one is not found it crashes. I am not sure if it crashes inside our outside of the weapon scan loop. I am guessing inside being that I did not see an echo inside the console that I had directly following the loop.

Code:
//If the weapon that's being removed is mounted
	if (%this.weaponShape[%slot] == %this.getMountedImage(0).getName())
	{
		//Un-mount the weapon
		%this.unMount(%weapon);

		//Mount new weapon (if you have it)
		[b]for (%x = %slot - 1; %x > 0; %x--)
		{
			if (%this.weaponSlot[%x]) //Do you have a weapon in that slot?
			{
				%this.useWeapon(%x); //Mout it
				break; //Exit loop
			}
		}[/b]
	}

Thanks!

#1
12/18/2005 (12:39 pm)
Well to start with, your first if conditional is never going to return true. You look to be comparing two string values with a == where you should be using $= for string compares (since you're using getName() I assume that's what you mean to do). And that's assuming those variables are giving you the values you want, which I would echo out to see if they are. It's wholly possible it's getting names and converting to their IDs which could still work, but meh.

if (%this.weaponShape[%slot] == %this.getMountedImage(0).getName())
//should be
if (%this.weaponShape[%slot] $= %this.getMountedImage(0).getName())
#2
12/18/2005 (12:49 pm)
Well, it does return true. :P

EDIT: Bolded problem loop.
#3
12/18/2005 (1:22 pm)
Hmm... I've been looking into it more and it seems the loop may not be the problem. Yet I don't understand what the problem could be.
#4
12/18/2005 (1:32 pm)
Problem found. Sorry to post this. It was a muzzle vector problem (there was no muzzle point).

Stupid me.