Difference between revisions of "Debug Scripts"
Made note of RuDE
imported>AdiBeiElderScrolls |
imported>Shademe (Made note of RuDE) |
||
(12 intermediate revisions by 8 users not shown) | |||
Line 1: | Line 1: | ||
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. | |||
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 | 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 | 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 87: | Line 87: | ||
</pre> | </pre> | ||
But the script saved without any problems and ingame I didn't get a message that something went wrong. This is because the compiler frequently ignores extra parameters. For instance, these lines, while incorrect, compile fine: | |||
<pre>disable objectID 1 | <pre>disable objectID 1 | ||
PickIdle My name is Bob</pre> | PickIdle My name is Bob</pre> | ||
: | :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) | ||
<pre>GetCurrentAIPackage " | <pre>GetCurrentAIPackage "ValidPackageName" | ||
PickIdle My name is Bob</pre> | PickIdle My name is Bob</pre> | ||
:Or | :Or | ||
<pre>If ( GetCurrentAIPackage " | <pre>If ( GetCurrentAIPackage "ValidPackageName" ) | ||
PickIdle My name is Bob | 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 | 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 170: | Line 177: | ||
</pre> | </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]] |