Debugging
When something just isn't working right, look here for possible causes and ways to track down the bug.
Comma Instead of Period
This can cause severe headaches for the scripter: The compiler will accept a comma in place of a period in reference syntax, but the script will silently fail in the game when the line is encountered.
player.modAV health 200 <- Fine player,modAV health 200 <- Suddenly your script is no longer running and you're wondering why
Easy to miss when you're looking for logic errors.
Numerals
Don't start an ID or variable with a numeral.
short 5forFighting; BAD long benFolds5; GOOD! myGuy.moveTo 0marker; BAD
Mismatched If/Endif
The compiler will ignore extra endifs when you save your script, but they can cause the script to stop running when encountered during gameplay. Make sure each if in your script is paired with exactly one endif:
if ( something == happened ) do something endif ; GOOD endif ; BAD, extra endif may cause errors in the game
The best way to avoid this problem is to use proper indentation of if-blocks.
Quest Topic Scripts
The Scripting section in the Quest/Topic editor seems to be for very generic scripting like setting global variables and doing things like setstage. Be aware that while some things may compile clean here and seem perfectly fine, they just don't work in-game.
Getself != player
Be careful if you use:
Getself != player
When called in a scripteffect spell, the statement sometimes evaluates true for the player. The easiest solution is to add another condition to double-check it, such as:
getdistance player > 0
However, getDistance is unreliable if the player is swimming. The best solution is to use:
ref refVar set refVar to getSelf if ( refVar.getIsReference player == 0 )
Using PlaceAtMe's referenced item in the same frame
If you use the referenced item of a PlaceAtMe call in the same frame
set pItem to (player.PlaceAtMe IronBow 1, 0, 0) pItem.Activate player ;this adds the bow to the player
the script on the object may not run.