Non-deterministic script behavior has driven John Moonsugar

Post » Sun Jul 22, 2012 8:44 am

If you ever play Arktwend, and you see http://morrowind.nexusmods.com/mods/images/28293-5-1259002633.jpg, that's poor John Moonsugar who was driven off the deep end by Morrowind scripting.

I had a simple script for a guard on a prison ship. He's supposed to wait by a timer for 10 seconds, then AITravel past the player's prison cell, when he's near, give a forcegreeting, finish his AITravel, then go back to where he started from. Everything else being the same from one run of the game to the next he would sometimes do this correct behavior, and sometimes he would skip the wait, and travel past the player without giving his forcegreeting. I'm able to make the script robust enough that the dialogue that needs to happen does happen, but the fact that the script has 2 different behaviors really bothers me.

I was just wondering if anyone else has had to deal with scripts that function differently from one run of the game to the next?

The "robustified" script, for the curious, with extra code in states 2,3,4 to handle the bugged behavior:
Spoiler

Begin GaleoneWache01NPCShort StateFloat Timerif ( State == 0 )	"GaleoneZettel01"->Disable ; Gets Enabled via GaleoneWache01's dialogue	Set Timer to 0	Set State to 1elseif ( State == 1 )	Set Timer to ( Timer + GetSecondsPassed )	if ( Timer > 10 ) ; Wait a short bit		;; First AITravel		AITravel 1250 3575 832 ; Then walk past player in cell		Set State to 2	endifelseif ( State == 2 )	If ( GetDistance "GaleoneZettel01" < 120 )		if ( GetJournalIndex "A_II_Galeone" < 2 )			ForceGreeting ; Taunt player when near			Journal "A_II_Galeone" 2			Set Storyvar to 9			Set State to 3		endif	endif	if ( GetAIPackageDone ) ; first AITravel to finishes		;; if we got here, somehow the GetDistance stanza above did not trigger !!		Set State to 4	endifelseif ( State == 3 )	if ( GetAIPackageDone ) ; wait for first AITravel to finish		Set State to 4	endifelseif ( State == 4 )		if ( GetJournalIndex "A_II_Galeone" < 2 ) ; In case previous condition in state 2 was not met			ForceGreeting ; Taunt player when near			Journal "A_II_Galeone" 2			Set Storyvar to 9		endif		;; Second AITravel		AITravel 2176 3584 832 ; then go back to guard's starting point		Set State to 5	endifelseif ( State == 5 )	if ( GetAIPackageDone ) ; wait for second aitravel to finish		AIWander 1000 5 0 0 60 20 10 0 ; and now just wander		Set State to 999 ; Done	endifendifEnd
User avatar
Oscar Vazquez
 
Posts: 3418
Joined: Sun Sep 30, 2007 12:08 pm

Post » Sun Jul 22, 2012 9:38 am

I
I've had scripts behave differently like that, and I have a pet theory, though it's unproven. GetDistance seems to be one of the common ingredients with odd behavior, I sometimes wonder if the graphics animations continue while the script is held up looking for getDistance results, sometimes moving the target beyond the window of range.

I had a script that was supposed to cause an effect hen the PC walked by an activator placed near a door. Like you, I had set the distance to 128 for the trigger, and... It was then possible for the PC to activate the door before ever coming within the scripted range, thus circumventing the script. Fine, I moved the activator farther from the door so the PC had to be within range before they could activate the door. Only... sometimes it worked, and sometimes it didn't.

While 128 should be the equivalent of 5 to 6 feet, in practice, this seems to vary - and vary by quite a bit. The script would fire properly if the PC passed by it, but only if the range was 200 or a little more (I tend to use 256 as the step up from 128). This sometimes resulted in the script triggering a bit earlier than I wanted, but better early than never, eh? I then moved the activator back toward its original position perhaps 50 gu, and it worked well thereafter.

If your guard walks on by, I suspect that as far as the game is concerned, the trigger range is never crossed for one reason or another.
User avatar
Georgia Fullalove
 
Posts: 3390
Joined: Mon Nov 06, 2006 11:48 pm

Post » Sat Jul 21, 2012 8:00 pm

GetDistance seems to be one of the common ingredients with odd behavior,
Shoot me now, Arktwend uses GetDistance a lot :) I previously thought it was very reliable, but something's definitely whacky.

It does sound like we encountered a similar problem. Maybe I should break up his travel into 2 stages.
User avatar
Skivs
 
Posts: 3550
Joined: Sat Dec 01, 2007 10:06 pm


Return to III - Morrowind