Lua scripting comment format / bug from word wrapping

Discussion on the Lua Scripting capabilities for RaceCapture/Pro. Also see the <a href="http://autosportlabs.net/RaceCapturePro_Lua_Scripting">Lua Scripting Guide</a>

Moderators: JeffC, stieg

Post Reply
VPD
Posts: 36
Joined: Sat Aug 11, 2018 1:40 pm
Location: NC

Lua scripting comment format / bug from word wrapping

Post 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.

brentp
Site Admin
Posts: 6274
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

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,
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

VPD
Posts: 36
Joined: Sat Aug 11, 2018 1:40 pm
Location: NC

Post 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.

brentp
Site Admin
Posts: 6274
Joined: Wed Jan 24, 2007 6:36 am

Post 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,
Attachments
Lua_scripting_presets.png
Lua_scripting_presets.png (79.35 KiB) Viewed 4545 times
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

Post Reply