0 votes
by (600 points)
Is there a way of pausing the execution of a passage so that the state of variables may be determined? This would be tremendously useful in debugging.

1 Answer

+1 vote
by (44.7k points)
selected by
 
Best answer

Mostly no, but there is an exception.

You can use the JavaScript alert() method to pause execution while displaying information.  So, for example you could do:

<<set $somevar = $somevar * $othervar>>
<<run alert("1: $somevar = " + $somevar)>>
<<set $somevar = $somevar * $anothervar>>
<<run alert("2: $somevar = " + $somevar)>>

And that would pause execution to show you the value of $somevar at both those points.

However, often a simpler solution it to just temporarily display those values on the page, like this:

<<set $somevar = $somevar * $othervar>>
1: somevar = $somevar
<<set $somevar = $somevar * $anothervar>>
2: somevar = $somevar

And you can tell what the value of $somevar was at both of those points.

If you don't want to display that data on the screen, you could display it in the console instead using the console.log() method like this:

<<set $somevar = $somevar * $othervar>>
<<run console.log("1: $somevar = " + $somevar)>>
<<set $somevar = $somevar * $anothervar>>
<<run console.log("2: $somevar = " + $somevar)>>

(In most browsers you can open the console using the F12 key.)

Those are the three main ways I debug variables like that.

Hope that helps!  :-)

...