Page 1 of 1

Lua scripting comment format / bug from word wrapping

Posted: Wed Feb 27, 2019 6:47 pm
by VPD
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.

Posted: Tue Mar 05, 2019 6:05 pm
by brentp

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.


Posted: Tue Mar 05, 2019 9:09 pm
by VPD
Thanks Brent. I'm using the latest app.

By Script presets you mean the ability to load from the cloud or some other new feature? I'm using Wifi instead of Bluetooth to connect to RC, so I've not been able to try the cloud icon. If this is what you mean, guess I need to try out Wifi client mode.

Posted: Thu Mar 07, 2019 11:26 pm
by brentp
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,