Script: Trouble with AIPlayer.pushTask()
by Mark Storer · in Torque Game Engine · 09/06/2005 (2:21 pm) · 6 replies
I'm trying to push a "setMoveDestination" task, and having trouble.... Much like in this thread here. However, there's a big difference:
The suggestions there don't help. Gah!
I'm echo()ing my command string before trying to eval() it. Everything looks fine. "1234.setMoveDestination( "123.0 456.0 789.0" );". As you might imagine, those aren't the real numbers.
The first time throug, my echo revealed that I had two semicolons and no quotes. Inserting the quotes, and varying the number of semicolons (0 and 1) didn't help. A nigh-identical line of code without the pushTask works fine. My AI bot will gleefully charge off to the location of the last crossbow bolt's impact (I'm poking around with the AI inside the crossbow bolts 'I hit something' script, the name of which eludes me). This lemming-like behavior is amusing, but not what I want.
But with the pushTask, I get a "Syntax error in input" message for every attempted command (and since I've converted the crossbow to an unlimited-ammo machine gun for testing purposes, that's a lot of syntax errors).
Why doesn't the above-mentioned thread help? The only straw I can grasp is this: I'm using the "Enhanced Telnet Debugger". But the only bug I've ever heard about that was one relating to variables not being properly expanded. My pre-eval echo shows that everything is in order... with all the variables alread expanded into the string (as in the sample a few paragraphs up).
Suggestions?
The suggestions there don't help. Gah!
I'm echo()ing my command string before trying to eval() it. Everything looks fine. "1234.setMoveDestination( "123.0 456.0 789.0" );". As you might imagine, those aren't the real numbers.
The first time throug, my echo revealed that I had two semicolons and no quotes. Inserting the quotes, and varying the number of semicolons (0 and 1) didn't help. A nigh-identical line of code without the pushTask works fine. My AI bot will gleefully charge off to the location of the last crossbow bolt's impact (I'm poking around with the AI inside the crossbow bolts 'I hit something' script, the name of which eludes me). This lemming-like behavior is amusing, but not what I want.
But with the pushTask, I get a "Syntax error in input" message for every attempted command (and since I've converted the crossbow to an unlimited-ammo machine gun for testing purposes, that's a lot of syntax errors).
Why doesn't the above-mentioned thread help? The only straw I can grasp is this: I'm using the "Enhanced Telnet Debugger". But the only bug I've ever heard about that was one relating to variables not being properly expanded. My pre-eval echo shows that everything is in order... with all the variables alread expanded into the string (as in the sample a few paragraphs up).
Suggestions?
About the author
#2
PS: I had the second parameter, but had no idea what it did.
09/06/2005 (4:58 pm)
I'll give the "no quotes, just a comma" thing a shot when I get home tonight. Thanks. If that doesn't work, I'd be happy to post The Actual Code.PS: I had the second parameter, but had no idea what it did.
#3
Okey doke. Here's my code:
The commented code was there as sanity checks. I made sure I had the function name right, the escaping, and so on. And yes, I did watch Hogan's Heroes fanatically when I was a kid... why do you ask?
I also added an echo to my executeTask, thusly:
I've tried several variations on the above "pushTask"... in doing so I've received echo output bearing a striking resembalance to the following at one time or another (from memory, bear with me):
I only received the "I know NUSSINK" output early on before setting up the global AIManager... no problems since. I also haven't tried to give dead Kork an order. Insult to injury and all that.
Aside: A dead object that hasn't faded-n-been-deleted would still pass the "isObject" test, wouldn't it?
Back to the point, it's my understanding that both the 2nd and 4th lines of output above should give me something other than a "Syntax error in input" (in bright red text). Uncommenting the direct call to "setMoveDestination( %pos, false )" works fine. The AIPlayer is accessible, and does indeed have that particular method.
Stumped.
Anyone? Anyone? Beuller?
--Mark
09/07/2005 (8:43 am)
Okay. Gave the above code a shot. No such luck.Okey doke. Here's my code:
if (isObject($AIManager.player[0])) {
$AIManager.player[0].//setMoveDestination( %pos, false );
pushTask( "setMoveDestination(\""@ %pos @ "\");" );
//%player.pushTask( "setMoveDestination(\" " @ %Node2Pos @ " \")");
} else {
echo( "I know NUSSINK!" ); //</schultz>
}The commented code was there as sanity checks. I made sure I had the function name right, the escaping, and so on. And yes, I did watch Hogan's Heroes fanatically when I was a kid... why do you ask?
I also added an echo to my executeTask, thusly:
function AIPlayer::executeTask(%this,%index)
{
%this.taskCurrent = %index;
%taskStr = %this.getId() @ "." @ %this.task[%index];
echo( "executing task: '" @ %taskStr @ "'" );
eval( taskStr );
}I've tried several variations on the above "pushTask"... in doing so I've received echo output bearing a striking resembalance to the following at one time or another (from memory, bear with me):
1) 123.setMoveDestination( 0 0 0 );; 2) 123.setMoveDestination( "0 0 0" ); 3) 123.setMoveDestination( "0 0 0" ) 4) 123.setMoveDestination( "0 0 0", false ); 5) 123.setMoveDestination( 0 0 0, false ); 6) 123.setMoveDestination( 0 0 0, false )
I only received the "I know NUSSINK" output early on before setting up the global AIManager... no problems since. I also haven't tried to give dead Kork an order. Insult to injury and all that.
Aside: A dead object that hasn't faded-n-been-deleted would still pass the "isObject" test, wouldn't it?
Back to the point, it's my understanding that both the 2nd and 4th lines of output above should give me something other than a "Syntax error in input" (in bright red text). Uncommenting the direct call to "setMoveDestination( %pos, false )" works fine. The AIPlayer is accessible, and does indeed have that particular method.
Stumped.
Anyone? Anyone? Beuller?
--Mark
#4
it will help you.
09/07/2005 (11:28 am)
Here's code straight from the Warzone demo. Its not calling setMoveDesination but maybeit will help you.
function aiGuyTwo::activate(%this)
{
%this.mountImage(TracerRifleImage, $WeaponSlot);
%this.setInventory(TracerRifleAmmo, 10000);
%this.pushTask("followPath(" @ %this.path @ ",100)");
%this.pushTask("aimAt(hover2)");
%this.pushTask("wait(10)");
%this.pushTask("fire(true)");
}
#5
Thanks again.
09/07/2005 (1:57 pm)
Sadly, no. I'll rip out the enhanced debugger stuff and see if that makes any difference.Thanks again.
#6
Anyway, it works now.
I tried a number of steps to make sure various things worked along the way:
Based on that last line, I concluded that my "executeTask" had been mangled in some way, so I copied over my modified version with the one from my backup directory. Works fine now.
I was a little miffed to discover that "pushTask" doesn't actually let you que up a list of commands. It automatically executes the latest one, unless the current task index is an empty string. Non-intuitive, so I rewrote it to do what I expected.
So now I've got kork dancing around in circles, following all the positions on the map I have shot. Yay me.
Thanks for your help Robert.
09/07/2005 (10:43 pm)
After poking around for quite some time, I've concluded that I managed to funk up "executeTask" somehow. The original source had a ';' at the end... which shouldn't really matter if I'm including it in the task itself, but ah well.Anyway, it works now.
I tried a number of steps to make sure various things worked along the way:
eval( "echo( \"blah\" );" ); // yep eval( %player @ ".foo();" ); // yep again, I added a function with only %this as a param eval( %player @ ".echo( \"hello world\" );" ); // another function I added, to the player. just a pass-through really eval( %player @ ".setMoveDestination( \"@%pos@\", false );" ); // THIS worked.
Based on that last line, I concluded that my "executeTask" had been mangled in some way, so I copied over my modified version with the one from my backup directory. Works fine now.
I was a little miffed to discover that "pushTask" doesn't actually let you que up a list of commands. It automatically executes the latest one, unless the current task index is an empty string. Non-intuitive, so I rewrote it to do what I expected.
So now I've got kork dancing around in circles, following all the positions on the map I have shot. Yay me.
Thanks for your help Robert.
Torque 3D Owner Robert Blanchet Jr.
%position = "0 0 0"; %slowDown = false; %theAI.pushTask("setMoveDestination(" @ %position @ "," @ %slowDown @ ")");