go to Part:   previous   next   1   2   3   4   5   6   7   8   9   10   11 

Patterns Part 5

Debugging

Fasten your seatbelts:  we're going to do some debugging before we go on.

It's because we're going to be in trouble, and then we have to know how to get out of trouble.

Open the Patterns stack and go to programming mode.
Select Tools—>Application Browser.
Select the Go! button and open its script.

With the script window active, the menus have changed. You should be able to select Debug—>Script debug mode.

Note how the script window now has a grey bar at the left:

Our first breakpoint

Click at the "if" line, a red dot should appear:

That is called a breakpoint.  It's a signal we plant there to make the program stop so that we can then look at what has happened.

Now go back to run mode and click the "Go!" button.

Immediately the script window pops to the front and it highlights the breakpoint line:

My highlights are yellow, yours are probably light blue, but that's not important.

The program stops at the red dot.  The script window also gets buttons at the bottom:

Before clicking any of those buttons, select Debug—>Variable Watcher:

It's getting crowded on the screen:  yet another window pops up, the variable watcher:

In the variable watcher we can see all the values of all the variables.  In our case here, we have only two containers (variables), they are called lH and lW.  So far they are empty.

Now click the Step Into button on the script window once.  The program does one step:

The highlighted line goes down by one.  Note that on the stack window the image is now deleted.

The third line, put the width ... has not been done yet, it is waiting.  Pres the Step Into button once more.  The variable watcher now shows a value for lW, because the program went to get the width of the stack and put it into the container (=variable) called lW:

In my case the window was 341 pixels wide, in your case it may be different.

The highlighted line has not moved, because there is another step to be done on the same line:  getting the height.  Press the step-into button again.  We now see:

Press once more:

The line Choose rectangle tool has now been done, the repeat line is waiting.  The rectangle tool is chosen and we can see in the tools palette that both arrows at the top are now white (unselected) and the rectangle at the bottom is blue (selected):

Excellent. Press the step-into button once more.  The highlighted line jumps to after the end of the repeat block.  Why is that?  Because the mouse is up. Unfortunately we cannot click the step-into button and also hold the mouse down.  So that's it:  we can't really see things happen!

Press the Abort button.  Then select the run arrow in the tools palette.

Frigging it

Well, we can frig it!  Change:

  repeat while the mouse is down

 

to:

  repeat 4 times

 

Apply the change, make sure the red dot is still in the right place, and then press the Go! button.

Then keep pressing the Step Into button and observe on the stack window what happens as you keep clicking.  Also watch where the highlighted line goes.  It should go up and down the repeat block four times and then it should go down the rest of the script.

You can change the number 4 to a higher number if you want more of this, but I get bored quickly.

Watch out

Don't save this stack.  Or if you want to, set the repeat back to repeat while the mouse is down.  Also click the red dot to remove it.  Then you can save the stack.

This part was not very exciting, but we really need to know how to use the debugger to go on.

(next part)