Breakpoints in LiveCode
Breakpoints in LiveCode

This article is reprinted from RunRevPlanet's "52 tips", a great resource for LiveCode developers.

 

Breakpoints in LiveCode can do more than stop at a specific line during execution. With watches and conditional breakpoints in the LiveCode IDE you have access to two powerful tools to help you debug your applications.

 

Breakpoints in LiveCode

If lyou spend a lot of time in the Script Editor of LiveCode you know about setting breakpoints by clicking in the left hand gutter next to the line numbers. With the breakpoint indicated by the red circle. When a handler reaches a breakpoint during execution, the execution of the handler stops at the line of the breakpoint with the Script Editor showing the line. So you can then step through the code or inspect the variables.

 

Using breakpoints in this way is useful for debugging and checking or understanding the way code works. But there is more to breakpoints than just being able to stop at lines in your handlers. In LiveCode you also set:

  1. Conditional Breakpoints
  2. Watches

The Breakpoint pane at the bottom of the Script Editor is the easiest way to be able to set both of these breakpoints. With a conditional breakpoint execution stops when the breakpoint line is reached and if a conditional is true.

You set the condition by clicking on the pencil icon on the line of the breakpoint and entering in the dialogue the condition that you want checked as a trigger for the breakpoint.

Setting a conditional breakpoint

Conditional breakpoints are useful when you have a line that is executed many times, but you are only interested in examining the state of the program when a variable reaches a certain value. Conditional breakpoints are a big time saver, but the condition of the breakpoint is associated with a specific line of your code.

But what if there is variable that is being set to a particular value which indicates a problem or buggy behaviour, but you don't which line in your code is setting it. The variable may be set in many different places in your code. It could be a stack variable, or a global variable that is used across your application.

With LiveCode you don't need to set a breakpoint with a condition on every line in your application that sets the variable. Instead you can set a watch by right clicking (control click) in the Breakpoints pane and choosing New Watch from the contextual menu.

 

A watch is a special breakpoint that monitors a variable and if the value stored in it changes, execution is stopped at the line in your code where the variable was set to a different value.

Watch breakpoint

 

This is the tip for this week.

  • Watches are a powerful feature of LiveCode for debugging your application. A watch is like a global breakpoint that can stop the execution of your code anywhere, depending on the value in a variable.

As with normal breakpoints a watch can also have a condition which means that it will only be triggered when the watch variable is changed and a condition is true.

About The Author
Scott McDonald
Scott McDonald uses LiveCode for work and play. When not coding at Scott McDonald Personal Computer Services, he writes the blog at LiveCode Game Developer.
Read Scott Mcdonald's Blog
Other Articles
RunRevLive.14 Report
   12.09.2014
Get a flavour of RunRevLive.14, with some great photos of sessions, staff, attendees and the surroundings in San Diego.
Read more
 
 
Community Baked Pi
   12.09.2014
What's next for the Raspberry Pi edition of LiveCode? This popular little platform is making great strides with the help of the LiveCode Community.
Read more
33 Voices, Maths and the BBC
   12.09.2014
See Kevin Miller's interview with 33 Voices and learn how a LiveCode app is taking the pain out of maths across the globe. 6.6.3 is released with a patch for iOS builds.
Read more
Breakpoints In LiveCode
   12.09.2014
If you haven't worked out how to use breakpoints in LiveCode, this handy tutorial will show you how it's done.
Read more
 
Thank you for your time.

 

© LiveCode 2014