Jump to content


Photo

How to gather clues when debugging stuttering


  • Please log in to reply
25 replies to this topic

#1 the bigg

the bigg

    2083 is a prime number.

  • Modder
  • 3331 posts

Posted 24 May 2008 - 04:56 AM

The most common cause of stuttering characters (that is, characters who stop walking 'without reason') is a script block which fires multiple times and causes the character to stop his current action (Dialogue() when there's no valid entry state is a common example, but not the only one). With this short tp2 code and instruction uses, I hope to help you research with more ease which script block is actually causing the problem. It only gives you a nudge in the 'right' direction, but not the full solution (and in some cases, stuttering is caused by a conflict animation or something completely different anyway).

This tutorial assumes you know the fundamentals of modding (creating a tp2, viewing/reading game resources and variables, understanding scripts). Also, correctly running this code requires a WeiDU feature that is only available in WeiDU 207 or later. PM me if you need the beta for the purposes of this tutorial. It is possible to do a similar thing with WeiDU 206, but it will be much more cumbersome to use, since you'll get printed a random TLK string rather than the script file and block number.

Steps:
1) open your save game, view the creature file that is affected by the stutter, and write down a list of the script files it has as well as the script for the area you're in.

2) create a tp2 like the following one, edit the stuff I marked in the comments, and install it:
BACKUP ~stutter_test/backup~
AUTHOR ~blah~

BEGIN ~Test stuttering~
COPY_EXISTING ~scriptfile1.bcs~ ~override~ // be sure to change the file names to point to the relevant ones
	~scriptfile2.bcs~ ~override~
	~scriptfileN.bcs~ ~override~
	~AreaScript.bcs~ ~override~ // ditto
	~Baldur(25?).bcs~ ~override~ // use either baldur.bcs or baldur25.bcs wether you're in SoA or in ToB.
	SET x = 0 - 1
	DECOMPILE_BCS_TO_BAF
		REPLACE_EVALUATE ~\(RESPONSE #[0-9]+\)~ BEGIN
						x += 1
				END "\1
		ActionOverride(Player1,DisplayString(Myself,~Running block %x% of %SOURCE_RES%.BCS~))"
	COMPILE_BAF_TO_BCS

3) load up your game. You'll see the dialogue window spammed with lines like:
<CHARNAME>: Running block 5 of BALDUR.BCS
<CHARNAME>: Running block 123 of DPLAYER2.BCS
etc.
These lines identify which BCS blocks are running. Wait for a bit (30 seconds are fine), and see which ones fire only once, and which ones are firing endlessly. The latter ones are more likely the cause of your stuttering issues.

4) If you don't get repeating blocks, it's time to get bored and add more scripts to the list. Try adding your party members' scripts to the list in step 3. If that doesn't work, try adding all the scripts for all creatures in the area (someday I could write code to automate this as well) - although by this point you'll get spammed by tons of unrelevant AI blocks firing off.

5) Open up those scripts in your favorite game editor (or decompile them with WeiDU and read their contents in your favorite text editors). Try to identify which of those blocks are affecting your stuttering character, and why are they causing him to stutter (is one firing a Dialogue() which doesn't display? Is he under a constant ActionOverride()? NoAction()? *CastSpell()?).

6) If step 5 didn't help identify your issues, try repeating step 4.

I hope this will be useful to some people, and all comments and criticsm (constructive or not) are very welcome. If possible, try to write your feedback in a public post rather than in a PM, so that it's accessible to more people.


This is the code that will run under WeiDU 206, probably all the way back to WeiDU 185. <CHARNAME> will fire off random item descriptions, dialogue lines, sound effects without associated printed dialog, etc. You'll need to decompile all the script files you listed (wether they fired off or not) and seek the tlk string that gets spammed in the dialogue window.
BACKUP ~stutter_test/backup~
AUTHOR ~blah~

BEGIN ~Test stuttering~
COPY_EXISTING ~sw1h01.itm~ ~override~
	SET x = 0
BUT_ONLY_IF_IT_CHANGES

COPY_EXISTING ~scriptfile1.bcs~ ~override~ // be sure to change the file names to point to the relevant ones
	~scriptfile2.bcs~ ~override~
	~scriptfileN.bcs~ ~override~
	~AreaScript.bcs~ ~override~ // ditto
	~Baldur(25?).bcs~ ~override~ // use either baldur.bcs or baldur25.bcs wether you're in SoA or in ToB.
	DECOMPILE_BCS_TO_BAF
		REPLACE_EVALUATE ~\(RESPONSE #[0-9]+\)~ BEGIN
						x += 1
				END "\1
		ActionOverride(Player1,DisplayString(Myself,#%x%))"
	COMPILE_BAF_TO_BCS

EDIT: fix suggested by Taimon in the comments at G3.

Edited by the bigg, 24 May 2008 - 06:09 PM.

Italian users: help test the Stivan NPC!

Author or Co-Author: WeiDU - Widescreen - Generalized Biffing - Refinements - TB#Tweaks - IWD2Tweaks - TB#Characters - Traify Tool - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics - Nalia Mod - Nvidia Fix
Code dumps: Detect custom secondary types - Stutter Investigator

If possible, send diffs, translations and other contributions using Git.


#2 Yovaneth

Yovaneth

    The newly-appointed Master Builder of Baldur's Gate

  • Modder
  • 3058 posts

Posted 24 May 2008 - 11:31 AM

Nice one, Bigg - a bloody useful tip.

-Y-

#3 berelinde

berelinde

    Troublemaker

  • Modder
  • 4916 posts

Posted 04 June 2008 - 05:24 PM

Good stuff. Sure beats adding DSH() manually to every script in the mod...

"Imagination is given to man to console him for what he is not; a sense of humor, for what he is." - Oscar Wilde

berelinde's mods
TolkienAcrossTheWater website
TolkienAcrossTheWater Forum


#4 jastey

jastey
  • Administrator
  • 3218 posts

Posted 06 June 2008 - 10:41 AM

You are my hero. Never to be afraid of stutter bugs! :Bow:

#5 jastey

jastey
  • Administrator
  • 3218 posts

Posted 05 December 2008 - 02:29 PM

Did I mention this destutter-tool rocks? :cheers:

#6 GeN1e

GeN1e

    A very GAR character

  • Modder
  • 1604 posts

Posted 06 December 2008 - 06:30 AM

Afaiu it won't work that precise when the script in question contains multiple RESPONSEs in one block. So, some manual work will be needed still.

Retired from modding.


#7 the bigg

the bigg

    2083 is a prime number.

  • Modder
  • 3331 posts

Posted 06 December 2008 - 06:46 AM

Read the introduction more carefully. In any event, it patches all RESPONSE branches.

Italian users: help test the Stivan NPC!

Author or Co-Author: WeiDU - Widescreen - Generalized Biffing - Refinements - TB#Tweaks - IWD2Tweaks - TB#Characters - Traify Tool - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics - Nalia Mod - Nvidia Fix
Code dumps: Detect custom secondary types - Stutter Investigator

If possible, send diffs, translations and other contributions using Git.


#8 GeN1e

GeN1e

    A very GAR character

  • Modder
  • 1604 posts

Posted 06 December 2008 - 07:38 AM

In any event, it patches all RESPONSE branches.

This I did get. My concern was, there'd be diversions with the string displayed and the block's actual number. Not really a big deal, though, as I think of it now - as there's no numeration of blocks displayed. Well, just a hasty post my previous one was.

Retired from modding.


#9 the bigg

the bigg

    2083 is a prime number.

  • Modder
  • 3331 posts

Posted 06 December 2008 - 08:40 AM

Actually, every single RESPONSE block counts - so, if you have two distinct RESPONSE blocks in the same IF section, they'll have a different number (the counter is increased each RESPONSE block, not each IF one). Please check before posting ;)

Italian users: help test the Stivan NPC!

Author or Co-Author: WeiDU - Widescreen - Generalized Biffing - Refinements - TB#Tweaks - IWD2Tweaks - TB#Characters - Traify Tool - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics - Nalia Mod - Nvidia Fix
Code dumps: Detect custom secondary types - Stutter Investigator

If possible, send diffs, translations and other contributions using Git.


#10 GeN1e

GeN1e

    A very GAR character

  • Modder
  • 1604 posts

Posted 06 December 2008 - 09:47 AM

For the sake of clarity :)


the counter is increased each RESPONSE block, not each IF one

Which would yield

IF //1st
Trigger()
THEN
RESPONSE #100
Action()
ActionOverride(Player1,DisplayString(Myself,~Running block 1 of MYSCRIPT.BCS~))
RESPONSE #100
Action()
ActionOverride(Player1,DisplayString(Myself,~Running block 2 of MYSCRIPT.BCS~))
RESPONSE #100
Action()
ActionOverride(Player1,DisplayString(Myself,~Running block 3 of MYSCRIPT.BCS~))
END

IF //2nd
Trigger()
THEN
RESPONSE #100
Action()
ActionOverride(Player1,DisplayString(Myself,~Running block 4 of MYSCRIPT.BCS~))
END

IF //3rd
Trigger()
THEN
RESPONSE #100
Action()
ActionOverride(Player1,DisplayString(Myself,~Running block 5 of MYSCRIPT.BCS~))
END

IF //4th
Trigger()
THEN
RESPONSE #100
Action()
ActionOverride(Player1,DisplayString(Myself,~Running block 6 of MYSCRIPT.BCS~))
END
I initially meant that seeing in the text window "Running block 4 of MYSCRIPT.BCS" would make a person to look for the fourth block of script, while in truth it'd be only the second one.
Of course, I didn't think well before posting - any sentient human being would apparently be able to find the block that says "Running block 4 of MYSCRIPT.BCS", even if it's located two positions closer to the top than one would expect.

Edited by GeN1e, 06 December 2008 - 09:48 AM.

Retired from modding.


#11 the bigg

the bigg

    2083 is a prime number.

  • Modder
  • 3331 posts

Posted 06 December 2008 - 10:45 AM

Yes, I can see how this is potentially unclear. If somebody wishes to word this more clearly, I'll be glad to update the tutorial.

Italian users: help test the Stivan NPC!

Author or Co-Author: WeiDU - Widescreen - Generalized Biffing - Refinements - TB#Tweaks - IWD2Tweaks - TB#Characters - Traify Tool - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics - Nalia Mod - Nvidia Fix
Code dumps: Detect custom secondary types - Stutter Investigator

If possible, send diffs, translations and other contributions using Git.


#12 Icendoan

Icendoan

    "An Infinite Deal of Nothing"

  • Member
  • 1723 posts

Posted 06 December 2008 - 01:18 PM

Change it to "Running Response X of MYSCRIPT.BCS", and anyone who knows enough to use the tool properly will understand that.

Icen
Proud member of the 'I HATE Elminster!' Club!

Mods in development: Keeping Yoshimo

#13 the bigg

the bigg

    2083 is a prime number.

  • Modder
  • 3331 posts

Posted 06 December 2008 - 04:59 PM

Cheers. I was assuming people were 'smart' enough to use Find to look for instances of "block xyz" rather than manually counting ;)

Italian users: help test the Stivan NPC!

Author or Co-Author: WeiDU - Widescreen - Generalized Biffing - Refinements - TB#Tweaks - IWD2Tweaks - TB#Characters - Traify Tool - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics - Nalia Mod - Nvidia Fix
Code dumps: Detect custom secondary types - Stutter Investigator

If possible, send diffs, translations and other contributions using Git.


#14 Chevalier

Chevalier

    Knight of the Realms

  • Modder
  • 2405 posts

Posted 06 December 2008 - 07:17 PM

I was assuming people were 'smart' enough to use


The dumber you think 'people' (not a person, but people in general) are the smarter you will appear.

I Ride for the King!


a.k.a. Chev


#15 devi

devi
  • Member
  • 34 posts

Posted 27 March 2009 - 11:45 AM

Any chance you can make this mod-newbie friendly ? I hardly understood 10% of all this due to insufficient modding knowledge, so all I'm asking is a little help with the steps. Anyone ?

#16 cmorgan

cmorgan
  • Modder
  • 2301 posts

Posted 28 March 2009 - 06:39 AM

devi, the problem is that you need to have a good idea of what you are looking for (in general terms) before you do this. If you just add it to all scripts, you will get way too much information, so it is really a coders tool for debugging specific instances.

Example:

Pretend I have Viconia stuttering in her first area in Amn when I pick her up after installing my beta mod.

So, I know that I have Player1, Minsc, and Jaheira in the party. I know Viconia is in the party. i know that they are in a specfic area, and she is stuttering.

Then, I follow the bigg's tutorial. I open up Notepad++, a copy of NI, and paste his code into NotePadd++, saving it as "testing.tp2".

I drop that file into my game directory into a new folder called "testing" with a new subfolder called "backup" and I put the .tp2 inside of the folder marked "testing".

I copy a setup-mymod.exe and rename it setup-testing.exe

I take a look at NI, and go back and forth between the various .cres and the scripts they are running, and add the values:

BACKUP ~testing/backup~
AUTHOR ~blah~

BEGIN ~St- t- tart St - tut - tering t- test~
COPY_EXISTING ~MINSC.bcs~ ~override~ // be sure to change the file names to point to the relevant ones
						 ~VICONIA.bcs~ ~override~
						   ~JAHEIRA.bcs~ ~override~
						   ~AR1000.bcs~ ~override~ // ditto
						   ~Baldur.bcs~ ~override~ // use either baldur.bcs or baldur25.bcs wether you're in SoA or in ToB.
	SET x = 0 - 1
	DECOMPILE_BCS_TO_BAF
		REPLACE_EVALUATE ~\(RESPONSE #[0-9]+\)~ BEGIN
						x += 1
				END "\1
		ActionOverride(Player1,DisplayString(Myself,~Running block %x% of %SOURCE_RES%.BCS~))"
	COMPILE_BAF_TO_BCS

Then I install the mod, by double-clicking on setup-testing.exe, and go back into BG2 and see what happens. The result will be a bunch of information in the dialog window.

The "old" way of trying to do this was setting up a number on each block of your own NPC's script, and setting a DisplayStringHead() so that your NPC walked around with a sequence of numbers floating over their head. You could also add numbers to your states, in dialog, so that there was a number associated there as well, for quick crossreference. It worked, and was very detailed - it told you exactly which actual block your NPC was playing at any given moment, so you knew that C-ARANJ was firing dialog state 14 and caling from .bcs block 27. But it didn't give you any help on what was interfering - it could diagnose your own code, and noone elses. This tool allows you to number and check all of the possible blocks in any script you care to add, so that you can see the whole picture - very important to finding incomaptibilities/scripting errors that cause stuttering.

Edited by cmorgan, 28 March 2009 - 06:39 AM.


#17 Jarno Mikkola

Jarno Mikkola

    The Imp in his pink raincoat.

  • Member
  • 10911 posts

Posted 12 April 2009 - 09:32 AM

... - although by this point you'll get spammed by tons of unrelevant AI blocks firing off.

Well, could this be done so the first 1000 strings are printed into a .txt file? So we could use it to see what strings pop up constantly if the game is loaded and has more than noticeable lagging/stuttering.

Deactivated account. The user today is known as The Imp.


#18 the bigg

the bigg

    2083 is a prime number.

  • Modder
  • 3331 posts

Posted 12 April 2009 - 09:56 AM

How are you going to redirect stuff to a file from within the game?

Italian users: help test the Stivan NPC!

Author or Co-Author: WeiDU - Widescreen - Generalized Biffing - Refinements - TB#Tweaks - IWD2Tweaks - TB#Characters - Traify Tool - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics - Nalia Mod - Nvidia Fix
Code dumps: Detect custom secondary types - Stutter Investigator

If possible, send diffs, translations and other contributions using Git.


#19 Wardibald

Wardibald
  • Member
  • 55 posts

Posted 25 January 2010 - 01:35 PM

Heya,



Beat me with teh noobstick for asking this, but:

What exactly is a block?

The reason I asked is bc I ran this mod on my baldur.bcs file, and ended up with info I can't rightly place.

More to the point:
I'm getting script blocks from 1141 to 1144 firing off endlessly, but I cannot find what that is in the script.

I've counted the IF's and END's on a hunch, but came up short. Only 1115 of each one.
Horum omnium fortissimi sunt Belgae - J. Caesar, De Bello Gallico

#20 the bigg

the bigg

    2083 is a prime number.

  • Modder
  • 3331 posts

Posted 25 January 2010 - 01:52 PM

You need to count the RESPONSE lines... or decompile using NI and/or WeiDU and search/find for the "block 1141" phrase.

Italian users: help test the Stivan NPC!

Author or Co-Author: WeiDU - Widescreen - Generalized Biffing - Refinements - TB#Tweaks - IWD2Tweaks - TB#Characters - Traify Tool - Some mods that I won't mention in public
Maintainer: Semi-Multi Clerics - Nalia Mod - Nvidia Fix
Code dumps: Detect custom secondary types - Stutter Investigator

If possible, send diffs, translations and other contributions using Git.