Example script from events section is not working

The example script from the events section (Preset Lua extension | Electra One Documentation) isn’t working:

function events.onPotTouch(potId, controlId, touched)
  print ("potId: " .. potId)
  print ("controlId: " .. controlId)
  print ("touched: " .. touched)
end

The problem is that the touched variable is of type bool and (pardon my c-lang-speak) casting that to a string doesn’t seem as straight-forward since I can see the following error in the log whenever that line is reached:

error running function ‘onPotTouch’: ctrlv2/slots/p001.lua:427: attempt to concatenate a boolean value (local ‘touched’)

Here’s what I’m doing instead and that works fine:

print ("touched: " .. (touched and 1 or 0))
2 Likes

The examples page was from an early revision of the Electra OS where the touched parameter was actually a 1 or 0 even though the docs said boolean.

Martin fixed the touched variable in a newer rev of the OS, but the docs were missed.
I’ve also used code similar to yours (after having it bomb out trying to print the boolean. lol)

Fixed the docs to handle the boolean correctly.