Rules and checklist
The rules that cause most errors
- Spaces around everything.
let a = b + 1. Leaving out a single space (b+1,a>1) is an error. - One operation per line.
let a = b + cis fine;let a = b + c - 1isn't. Use a spare variable for the middle step. - One value on the left of a comparison.
if a > b + 1 thenis fine;if a - 1 > b thenisn't. THENat the end of theIFline, body on the next line,END IFalways.ELSE,LOOP,NEXTandEND IFeach go on a line by themselves.- Your variables are
atoj, lower case. There are no others and no named variables. - No
AND/OR. NestIFs, or set a flag variable in severalIFs and test the flag once. - Keep nesting to 5 levels in total. The main
DOloop counts as one. The manual's wording leaves room for a little more, but 5 in total is safe. Flag variables keep nesting shallow. - 1,900 bytes, line endings included. Indentation and comments count too. Over the limit, the end of the script is silently lost.
ENDbefore any subroutines.- Errors can hide. The unit reports an error when it reaches the bad line. A typo inside an
IFthat hasn't been true yet won't show up until it is. The simulator and the vendor's checker both check every line up front, which is one reason to use them.
Before every upload
- Save what's on the unit now. Copy the script from the unit's Script tab into a dated text file. That's your rollback.
- Run it here. Check that it passes, then run the days that matter: a cold day, a mild day, a weekday and a weekend, midnight, and a power cut.
- Run the vendor's checker. ControlByWeb provides a Windows command-line BASIC checker (
cbw_basic, linked from their BASIC script tutorial). It is the authority on syntax. Note that after "syntax check passed" it starts running the script and doesn't stop on its own. - Upload under a new file name and make sure the script is set to run.
- Check the status. The Script tab should report the script running. If it reports an error, it names the line.
- Test one thing live. Press a button, change a setpoint, or wait for a time boundary, and watch the relay do what you expected.
- Keep notes. What changed, when, and how to roll back.
Things the unit does that surprise people
- Saving any setup page restarts the script. So does a power cut. Your variables
a–jand the timers start again from scratch. Write scripts that work out everything from the current time, sensors and external variables on each pass, rather than remembering state for long. - Relays after a power cut. The manual doesn't say what state relays come back in. Don't rely on a relay staying on through a power cut.
- External variables after a power cut. Also not documented. Values given on the setup page are the safe assumption; a value pushed in over the network may need pushing again.