Comments
Comments add notes for people reading the source code. Matchbox ignores them when it runs the program.
Single-Line Comments
Begin a single-line comment with #. Everything from # to the end of the line is part of the comment:
# Limit values received from the volume control
var volume = clamp(120, 0, 100)
A comment can also follow code on the same line:
var retries = 3 # Number of attempts before reporting an error
Use end-of-line comments sparingly. A comment on the line before the code is usually easier to read when the explanation is long.
Multi-Line Comments
Place ## before and after a comment that spans multiple lines:
##
Convert minutes to seconds here because the timer API
expects its duration in seconds
##
var timeout = minutes * 60
Writing Useful Comments
Comments are most helpful when they explain why the code exists, document an important constraint, or clarify a decision that is not obvious from the code itself. Avoid comments that only repeat what the next line already says.
# Keep the timeout below the service's 60-second limit
var timeout = min(requested_timeout, 60)
Keep comments accurate when the code changes. An outdated comment can be more confusing than no comment at all.
Next Step
Continue to Variables.