Difference between revisions of "Debug Scripts"

2,982 bytes added ,  11:29, 25 February 2011
Made note of RuDE
imported>AdiBeiElderScrolls
imported>Shademe
(Made note of RuDE)
 
(27 intermediate revisions by 8 users not shown)
Line 1: Line 1:
The debug process with CS is quite time consuming and the provided tools are not really satisfying.
Script debugging can be made easier with the use of [[:Category: RuntimeDEbugger|RuntimeDEbugger]], an OBSE plugin. It enables users to debug scripts as they execute in-game.  


So here are some hints for debugging scripts in case you have unexpected results.
General hints for debugging scripts:


===[[Script Processing]]===
===[[Script Processing]]===
Line 26: Line 26:
There are different ways to control the current content of your variables.
There are different ways to control the current content of your variables.


The most convenient and reliable way is using the [[:Category:Console Functions|Console Functions]], especially '''prid''' and '''tst''' or '''sv'''. You always will get the real current content.
The most convenient and reliable way is using the [[:Category:Console Functions|Console Functions]], especially '''prid''' and '''tst''' or '''sv'''. You will always get the real current content.


So, first activate or focus the object you want to examine (talk to your NPC, open the book ...) then open the console. You now will see in the upper part of the screen the '''formID''' of your object. If not, left-click the object with your mouse.
So, first activate or focus the object you want to examine (talk to your NPC, open the book ...) then open the console. You will now see in the upper part of the screen the '''formID''' of your object. If not, left-click the object with your mouse.


If the object you want to examine cannot be left-clicked (because it's in a different cell, or disabled), you can select with the '''prid''' command if you know its form ID. The '''prid''' command will change to any object given, so if you want to examine your NPC script and your NPC has shown a '''formID''' of 0b002089 you simply enter:
If the object you want to examine cannot be left-clicked (because it's in a different cell, or disabled), you can select with the '''prid''' command if you know its form ID. The '''prid''' command will change to any object given, so if you want to examine your NPC script and your NPC has shown a '''formID''' of 0b002089 you simply enter:
Line 92: Line 92:
PickIdle My name is Bob</pre>
PickIdle My name is Bob</pre>


Probably the circumstance, that object name was within apostrophes?
:And in fact, thats what's also true. But the GetCurrentAIPackage worked this time like a return function ... so it didn't execute any code above the first occurrence of GetCurrentAIPackage due to not using it correctly in a compare statement ... but using a valid package name ... just try (the package doesn't need to be related to the NPC)
Details: Using localized german versio, with Update German V1.1, Plugin Oblivion Deutsch 3.0, BTMod 2.20 - also maybe plugin malfunctions?
 
[[User:AdiBeiElderScrolls|AdiBeiElderScrolls]] 14:14, 13 November 2006 (EST)
<pre>GetCurrentAIPackage "ValidPackageName"
PickIdle My name is Bob</pre>
 
:Or
 
<pre>If ( GetCurrentAIPackage "ValidPackageName" )
  PickIdle My name is Bob
EndIf</pre>
 
:You may want to use the following test sequence with an NPC not related to the used package to verify the problem. You will notice, that the script can't be saved, if no valid package name is given. Also, it may happen, that the script afterwards won't execute anymore. In my case, FramesRun stayed at value 1, even if talking to the NPC - see details of my configuration below.
 
<pre>short FramesRun
Begin GameMode
 
Set FramesRun To FramesRun+1
Message "Test before GetCurrentAIPackage"
 
If ( GetCurrentAIPackage aaaCreatureExterior1500 )
  Message "Test aaaCreatureExterior1500 package name"
EndIf
 
Message "Still alive"
 
... other code
End</pre>
 
:So you see, some functions (especially that one's that can also work like a return function) may have unwanted behavior, not foreseen and others don't!
 
:Details about configuration: Using localized german version, with Update German V1.1, Plugin Oblivion Deutsch 3.0, BTMod 2.20


===Ingame starting debug messages at defined points===
===Ingame starting debug messages at defined points===
Line 106: Line 134:
   Message "whatever you want to say %.0f" MyVar
   Message "whatever you want to say %.0f" MyVar
EndIf
EndIf
... your code
If debugOn
  Message "whatever you want to say %.0f" MyVar2
EndIf
... and so on
; and if you want to have the messages for each frame
; slowly passing by, you add a ShowEnchantment at the
; beginning or the end of the GameMode block, like
If debugOn
  ShowEnchantment
EndIf</pre>
You may also want to start the debug session on a defined point in your code. Nothing easier than that:
<pre>short debugOn
; save setting, for avoiding to be overruled by topics
; comment it out, if necessary
Set debugOn to 0
... your code
... your code
If debugOn
If debugOn
   Message "whatever you want to say %.0f" MyVar
   Message "whatever you want to say %.0f" MyVar
EndIf
EndIf
... and so on</pre>
... your code
If YourConditionBlockToInspect
  Set debugOn to 1
  ; get from here on all your messages
  If debugOn
    Message "whatever you want to say %.0f" MyVar2
  EndIf
  ; and if you want to have the messages for each frame
  ; slowly passing by, you add a ShowEnchantment at the
  ; very end of the inspection block this time, like
  ShowEnchantment
  ; I didn't check in all cases, if ShowEnchantment works
  ; like a return function (Usually it works fine and not
  ; as a return function).  But be aware of scripts that 
  ; may not execute further than this point or comment it out ;)
  ; now stop getting messages for this frame
  Set debugOn to 0
EndIf
... and so on
</pre>
 
Alternatively, by using [[Oblivion Script Extender]], debug messages can be logged directly to the console through the [[PrintToConsole]] function. The messages printed thus offer many advantages, the prime being non-overlapping messages.
 
Messages displayed using [[Message]] and [[MessageEx]] can overlap with successive entries, thereby not displaying what's supposed to be.
 
In your final version you should remove any debug message and if debugOn blocks, as you deal with an interpreter. So the more statements you have in your code, the more time the script execution will take.
 


[[Category:Scripting]]
[[Category:Scripting]]
Anonymous user