[JW Lua] Using the 'Optional' code field in RGP Lua

Jan Angermüller jan at angermueller.com
Thu Feb 3 09:33:20 CET 2022


Although it already has been solved, I think the actual coding problem 
which doesn't have to do with the Optional code wasn't mentioned.
/local /in an if-block means that it is only visible within the if-block.

if tacet~=nil then
      local tacet_text=tacet
else
      local tacet_text="TACET"
end
print(tacet_text)   --always prints nil, because tacet_text is unknown

So if you want to keep this if-else-statement, the correct solution 
would be:

local tacet_text
if tacet~=nil then
      tacet_text=tacet
else
      tacet_text="TACET"
end
print(tacet_text)   --prints correctly

However Robert's suggestion is more elegant:
tacet=tacet or "TACET"

Jan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://jwmusic.nu/pipermail/jwlua_jwmusic.nu/attachments/20220203/cd35e194/attachment.htm>


More information about the JWLua mailing list