January 05, 2017

My Script Should Absolutely Work but it Doesn't

Debugging Checklist


Use watchers to make sure variable results are the expected ones.

Use the stepping button on the Script Editor Menu bar (it looks like a video player forward control) to run each statement in your script and watch the results as you move through them.

Use the "pause script" tile rather than the "stop script" tile so you can start, pause and debug ticking scripts with the AllScripts tool.

Check numeric values have matching decimal places set. By default number variables are set to a random integer with decimal places set to 0. Some properties have decimal places set to 2. For example, if Player's numeric value at cursor is 0.25 and Player's numeric value at cursor gets assigned to user variable var1 set to 0 decimal places the result will be rounded up to 1. If you then compare var1 to Player's numeric value at cursor the comparison will be false even though Player's numeric value at cursor was assigned to var1. This isn't a really common problem but I try to avoid it by setting matching decimal points in any variables and properties I am using in scripts. If you need to use numeric values that round to the nearest value not up use the round function.

Make sure all tiles that need replacing in statements have been replaced or replaced with the correct tile. This is probably the most common error I make.

If you rename objects, scripts or variables you must remove any tiles that reference them from all existing scripts first and replace them with the renamed tiles.

When looping through collections make sure the script doesn't attempt to move the cursor past the end of the collection. For example, if you have 5 elements in your collection and the loop increases the cursor value 6 times, the cursor will wrap to the beginning element before the script ends. This will likely cause an incorrect result in your script.

Make sure test comparisons are set up properly. Speech balloons are handy for checking this. Use the "object says abc" tiles for this and set the object to say true for the yes branch and false for the no branch and then step through the script. Speech balloons can also display variables so use whatever values suit the condition you are checking.

Make sure the correct object is calling the correct script. For example, if you have a script in an Ellipse object called doSomething and try to run it with "World do doSomething", it won't work. Use "Ellipse do doSomething". You can use "World tell all contents doSomething" but that will run the script in any object that has a doSomething script. Also make sure any player variables are set to the correct object.

If you are having trouble with a recursive loop try setting it up as a regular loop and step through it to make sure stopping conditions can be met. With recursive scripts statements placed in the wrong order can cause stopping conditions to fail.

If you still can't figure out what's wrong you can use Squeak's debugging tool. You can find tutorials on Squeak at Lawson English's YouTube channel playlist Squeak from the very start. You will need to convert your tile script to text through the Script Editor menu options and type "self halt." without the quotation marks at the point in the script you want to debug and then press ctrl-s to save the script. Run the script and the debugging dialogue will appear.



Last Updated.