OpenTX Lua question

rcboffa

New member
Hi All,

OpenTX Lua scripting question. I have a number of logical switches and special functions that I copy from model to model and I'm trying to create a script that I can run with each new model that will will create all of them. Basically a model init script. I've been able to use the model.setLocgicalSwitch() function but I can't find any reference for parameter values. For example:

model.setLogicalSwitch(2, {func=4,v1=1,v2=-99, ["and"]=24})
If I wanted to set v1 to be a switch position like SA- or L01 what would I pass in? Is there a lookup table that can tell me that 24 is SH↑ or whatever it is. I can probably figure out the physical switches, but I have no idea how to set it to another logical switch.

Thanks for any help,
Adam
 

LitterBug

Techno Nut
Moderator
I generally create a copy of a model and then tweak anything that must be changed rather than starting from scratch for each model. 98% of my settings are identical.
 

rcboffa

New member
I generally create a copy of a model and then tweak anything that must be changed rather than starting from scratch for each model. 98% of my settings are identical.

Yeah, this probably true for me as well. If this lua scripting doesn't work out, I will probably create a model that is just a template and then copy from it every time.
 

PsyBorg

Wake up! Time to fly!
You can also set everything up that will carry over to all your models into global variables. Then its just a matter of checking a box with each new model or telling opentx to use it for everything. @rockboy did a thread on this somewhere in here. Kinda busy atm to go hunt it down for you at the moment though.
 

rcboffa

New member
So I learned that you are supposed to be able to use a function called getFieldInfo() to get the numeric id that I was looking for. However the function is not always returning the correct number. This is what it looks like:

local ls4 = getFieldInfo("ls4")["id"]
model.setLogicalSwitch(0, {func=STICKY, v1=ls4, v2=sg_c})

The logical switch is showing LS51 instead of LS4.

One response came back on the OpenTX discord saying that the function was returning 123 and should be returning 76.

So it seems like getFieldInfo() has a problem. I might just abort mission.

Thanks for all the suggestions. Happy flying!