vfig on 14/3/2023 at 03:13
a problem i just had in my mission (still in the "AIWatchObj works sometimes" category, so i will describe it here) is an AIWatchObj pseudoscript that would sometimes seem to cancel itself. it would get halfway through its steps and then just not finish the rest of them—and there werent any alerts or anything like that happening to explain it.
my watch was set up with a radius of 4, and the second step was "Play sound/motion… Conv 42", which is the "squatting down" motion. the watch would always get as far as this step and the motion would begin, but some of the time the rest of the steps in the watch (doing a frob and removing a metaproperty, but not relevant) would simply not happen, and the ai would just go back to patrolling.
Quote Posted by R Soul
The AI checks the conditions of the link (distance, alertness) every fraction of a second (I'm not sure of the exact frequency).
being reminded of this—that the conditions are checked not just to start the pseudoscript, but repeatedly as it runs—put me on the right track.
i used this bit of squirrel to print the XY distance (as used for the Radius condition) and the Z distance (as used for the Height condition) every tenth of a second. "BookDropoffPt" here is the name of the marker which the AIWatchObj link goes to. and i used ai_flow_watch to log the ai actions.
Code:
class DebugDumpDist extends SqRootScript {
function OnSim() {
if (message().starting) {
SetOneShotTimer("DumpDist", 0.1);
}
}
function OnTimer() {
if (message().name=="DumpDist") {
local obj = Object.Named("BookDropoffPt");
local p1 = Object.Position(self);
local p2 = Object.Position(obj);
local dxy = vector(p1.x,p1.y,0.0) - vector(p2.x,p2.y,0.0);
local dz = vector(0.0,0.0,p1.z) - vector(0.0,0.0,p2.z);
print(":::::: "+dxy.Length()+", "+dz.Length());
SetOneShotTimer("DumpDist", 0.1);
}
}
}
here is what was logged:
Code:
[AI(2390) Watch: Flow] Pseudo-script: Play sound/motion(Sound Concept,Sound Tags,Motion Tags) ("", "", "Conv 42")
SQUIRREL> :::::: 3.89799, 1.02003
SQUIRREL> :::::: 3.92049, 1.02577
SQUIRREL> :::::: 3.97865, 0.955612
SQUIRREL> :::::: 4.05461, 0.747475
SQUIRREL> :::::: 4.09629, 0.485069
SQUIRREL> :::::: 4.09123, 0.250938
SQUIRREL> :::::: 4.07575, 0.011322
SQUIRREL> :::::: 4.05718, 0.233513
SQUIRREL> :::::: 4.04623, 0.455269
SQUIRREL> :::::: 4.04042, 0.618729
[AI(2390) Watch: Flow] changed goal to "'Goto Object or Location' [2399; (-9.095997, -190.925293, 104.155251) ] at priority 'Low'", ability "Patrol ability"
from this log i could see that during this motion, the ai's center moves backwards a little bit, enough so that the XY distance went back up over the 4.0 threshold just a little. and as a result, the pseudoscript stopped running because now the Radius condition was no longer met.
the fix i found: i made the first step of the pseudoscript be "Goto object" so that, although the watch starts when the ai enters the 4.0 radius, they walk significantly closer to the marker before beginning the motion, and so their distance from the marker now never exceeds approximately 2 feet.
(note: a "Goto object" with no arguments in an AIWatchObj pseudoscript will go to the destination of the link, in this case the BookDropoffPt marker itself. this doesnt work in Conversation or Response pseudoscripts, there you need an explicit argument for the object to go to.)