Difference between revisions of "Debug Scripts"

Jump to navigation Jump to search
136 bytes added ,  11:30, 13 November 2006
grammar and minor corrections
imported>AdiBeiElderScrolls
imported>Scruggs
(grammar and minor corrections)
The debug process with CS is quite time consuming and the provided tools are not really satisfying.
 
So here are some hints, howfor to debugdebugging scripts in case you have unexpected results.
 
===[[Script Processing]]===
First of all, you should take a look at the [[Script Processing]] article, to get a basic understanding, of how the different script types are workingwork.
 
Remember, that only quest scripts are considered to run constantly in a defined schedule.
 
Object scripts may run every frame, but they also may not execute for quite a while, if player is not near. Even thereThere are even cases, where AI packages prevent script running. This is true for Follow-Packages if they check on conditions related to script variables in the same object and these conditions are satisfied.
 
To find out, if your script is executed, simply put a code like the following into your script and control it afterwards ingame:
 
<pre>; use long, if you want to watch the frames
 
===Control variable content===
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.
 
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, point toleft-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:
 
<pre>prid 0b002089</pre>
<pre>sv</pre>
 
If you use many variables, you may only see the last ones. In this case, thatpress Page-Up to view the rest haveof beenthe declaredlist.
 
To get a special variable content, use the '''Show/tst''' command. So if you want to control how much times the script has executed until now, if you have set a FrameRuns variable, you just type:
<pre>show FrameRuns</pre>
 
If that variable is not getting bigger and bigger everytime you leave the console and enter it again, you may just have the case, that some AI package is preventing your script from running.
 
To see all of the variables within a particular quest, use '''ShowQuestVariables''' (or '''sqv''' for short):
'''Take care''', if you use [[Message]] or [[MessageBox]] functions inside of your script!▼
 
<pre>sqv QuestID</pre>
The delay of the [[Message]] function will cause, that the displayed values are not the current ones. Moreover, the first time every message is executed in the script, it will be delayed. Every further execution (next frame) leads to messages running at the top of screen to fast to follow. To make sure, that you can watch all messages for every frame, use some dialog function like [[ShowEnchantment]] at the end of the code block to examine.
 
▲'''Take care''', if you use [[Message]] or [[MessageBox]] functions inside of your script!
But always keep in mind, that the values shown in the message, are '''NOT''' the current values.
 
[[Message]] can be useful for showing which segment of code is executing, or the value of a variable at a particular moment, but because messages always stay on the screen for one second, consecutive messages will be delayed. This means the value of a variable displayed in a message may have changed before the message gets displayed. OBSE's [[PrintToConsole]] function can make debug messages easier to use.
[[MessageBox]] behaves in another way. If you want to have different message boxes, that pop up to show some variable content, you may end up with having only the last defined message box shown and all other ignored. ''Don't ask me why, but it seems to work this way''▼
 
▲[[MessageBox]] behaves in another way. If you want to have different message boxes, that pop up to show some variable content, you may end up with having only the last defined message box shown and all other ignored. ''Don't ask me why, but it seems to work this way''
 
At least [[MessageBox]] gives you the current values in the script.
 
===Find bugs not reported by CS or Oblivion===
CS usually gives you some hints, when you save a script. But this is not reliable at all. It only reports syntax errors, where- youfor tryinstance, referring to access objects, thatwhich definitelydon't doexist or are not existpersistent, or mismatched if-endif blocks.
 
You still can make syntax errors, that are not discovered or use functions, that work as a return statement.
 
Unfortunately, Oblivion does not provide any error messages within the game itself. If it encounters an error within a script, it will immediately terminate that script without notifying you. That's why it's useful to have a variable in your script that increments every frame - by checking that variable in the console, you can determine if your script has stalled.
Ingame you won't get a message about a problem, except that your script seems not to do, what it should do. But if the interpreter for the script finds some errors or return function, it will just cancel script execution at the point, where the error is found.
 
Here's an example: It took me a whole day to find out, why my script was not executed. And the reason was, that I mixed the commands [[GetCurrentAIPackage]] and [[GetIsCurrentPackage]].
 
So the statement
</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:
 
In this cases, it is recommended to use the [[Message]] function. Put a message after each code block to see, where the script stops execution, just like
 
<pre>If WhatEverCondition1
... your code
EndIf
Message "WhatEverCondition1 executed"
If WhatEverCondition2
... your code
EndIf
Message "WhatEverCondition2 executed"</pre>
 
<pre>disable objectID 1
--[[User:AdiBeiElderScrolls|AdiBeiElderScrolls]] 07:58, 13 November 2006 (EST)
PickIdle My name is Bob</pre>
 
[[Category:Scripting]]
Anonymous user

Navigation menu