Game Development Community

ConsoleMethod trouble

by Jeff Trier · in Torque Game Engine · 07/11/2003 (8:13 am) · 3 replies

I am trying to open up Jims 'fireWeapon' function (thanks Jim)to the scripting engine since I need my bots to be able to fire indipendantly without moving.

The fireWeapon function works as follows:
/**
 * Tells the AI to fire.
 */
void AIPlayer::fireWeapon(bool enable) { // Jimomighty
   // Fire the seclected weapon.
	
	if(enable)
	{
		mModeFire = true;
		throwCallback( "onShoot" );
	}
	else
	{
		mModeFire = false;
		throwCallback( "onUnshoot" );
	}
}


Now from what I have read and the examples I have seen, I came up with the below ConsoleMethod...

/**
 * Fire on Command   
 */
ConsoleMethod( AIPlayer, fireWeapon, void, 3, 3, "ai.fireWeapon(bool);"){
	AIPlayer *ai = static_cast<AIPlayer *>( object );
	ai->fireWeapon(dAtob(argv[1]));
}

This function is definatly being listed when I do a dump(), but it doesn't seem to function when I try and activate it. No errors or anything.

Here is the script:

function aiPlayer::BrainLoop(%this){ // Thanks to Dan's example!
echo("Scanning Object:" @ %this);

	cancel(%this.ailoop);
	%this.ailoop = %this.schedule(500, "BrainLoop");

	// scan for units
	%radius=$BotSightDistance;
	%position = %this.getPosition();
	InitContainerRadiusSearch(%position, %radius, $TypeMasks::PlayerObjectType);
	while ((%targetObject = containerSearchNext()) != 0)
	{
	echo("--------------------------------Scan Loop");
		//===================================================Daniel Neilsen's section
		if(%targetObject == %this)
			continue;
		if(%targetObject.getState$="Dead")
			continue;
	//=========================================================================
		echo("Object Scanned:" @ %targetObject @ "On Team:" @ %targetObject.ArmyID);
		

		if (%this.ArmyID != %targetObject.ArmyID){
			
			if (%this.Attitude == 0){ 
				
				
				echo("FIRING");
				%this.fireWeapon(true);
				//continue;
			}

... More code here...

The script will echo "FIRING", but nothing happens.

Any insight would be great!

-Jeff

About the author

Originally a Classical/Metal musician, I've always been attracted to anything involving computers, including: Networking, PC Building and Repair, software design and coding. I've been involved with game design and development for over 10 years.


#1
07/11/2003 (8:17 am)
Hmmm, I'm not scolding you but does your bot have a weapon and ammo? :D
#2
07/11/2003 (8:20 am)
Lol!

yes, plenty. :)

I guess I should have mentioned that other functions work. For instance, if I was to replace %this.fireWeapon(true); with %this.setAttackTargetObject(%targetObject);, it would run just fine.

EDIT: So am I to assume that I exposed the function correctly then?

Thanks for the quick response!
-Jeff
#3
07/11/2003 (8:49 am)
Hehe, ok I got it...


I didn't add a setAimObject first. I originally thought the weapon would just fire reguardless of a target.

Thanks!
-Jeff