When first setting up ShiftX2 I pasted in the Disco Lights Demo code from the website into RC using my phone and it didn't work. After quite a bit of time checking everything I finally discovered part of the comment line "--ShiftX2 library functions--" had wrapped so I had:
--ShiftX2 library
functions-- function sxSetLed(i,l,r,g,b,f)
which erroneously gave an undefined function and commented out the sxSetLed function. Not a big deal to fix once found, but leads to a series of questions.
1) The RC Lua script window appears to include word wrapping to scale to your screen size, makes sense. How does that effect / protect situations like this when pasting in code?
2) All other RC sample Lua code given has leading -- for comment lines, but this example also has trailing -- too. I think it's not needed in this case, but does Lua have a start and stop comment syntax like other codes that can be used to quickly (and safely?) comment out many lines at a time?
Edit: Found answer, use --[[ ]] Also suggested trick is use ---[[ --]] so the first '-' can be added/removed to quickly deactivate/activate that block.
3) This might have also been caused by word wrapping the code text in mobile browser view and pasting it in that way, switching to request desktop view might eliminates that. Is this more likely the root cause?
4) Can the RC app please allow access to the Lua script window when not connected to RC hardware? I'd like to debug things like this away from the car.
Lua scripting comment format / bug from word wrapping
Hi,
Thanks for the note.
Normally when the script is copied/pasted, the word wrapping should not be turned into line breaks. Something in the middle of the copy/paste operation might have done that.
Also, with the new app we have introduced the concept of Script presets, which loads the script cleanly, preventing any accidental line wraps. Be sure to check it out.
Thanks,
Thanks for the note.
Normally when the script is copied/pasted, the word wrapping should not be turned into line breaks. Something in the middle of the copy/paste operation might have done that.
Also, with the new app we have introduced the concept of Script presets, which loads the script cleanly, preventing any accidental line wraps. Be sure to check it out.
Thanks,
Hi, yes, it is a new feature in the latest app. Go to the script window, press "Presets" and you will see a list of script presets.
Be sure to press the cloud update button to get the latest.
The one loaded right now is the demo script which will work with your ShiftX2 (requires 2.15.0 firmware or higher).
Hope this helps,
Be sure to press the cloud update button to get the latest.
The one loaded right now is the demo script which will work with your ShiftX2 (requires 2.15.0 firmware or higher).
Hope this helps,
- Attachments
-
- Lua_scripting_presets.png (79.35 KiB) Viewed 9224 times