When trying to debug a program, it's useful to keep track of the current value of a variable or sprite property as the program runs. Sometimes you can use console.log()
to quickly report the value of a variable, but that's not so useful when you want to track multiple variables, or variables that change often during your program.
A watcher is a debugging tool that, as its name implies, watches your variables while the program runs, making it easier to see what they are doing.
Watchers are located in the Watch section of the debugging window, you may need to uncollapse this window to see it.
watch_me
with an initial value of 0. You can also use watchers to track sprite properties.watch_me
by 1. This will cause it to change 30 times a second.watch_me
.You can add watchers for any variable or object property by typing the name of a variable in the box and clicking the blue "add" button. If your program isn't running or the variable hasn't yet been assigned a value, the watcher will report a value of undefined
. This isn't an error, it just means that the variable hasn't yet been assigned a value.
Found a bug in the documentation? Let us know at documentation@code.org