Bitte ändert euer Passwort!
Im März 2026 wurde das Forum gehackt. Dabei hatten die Angreifer Zugriff auf die Datenbank und somit Zugriff auf eure Passwörter. Auch wenn das Forum kein Passwort im Klartext speichert, können die Angreifer eure Passwörter knacken. Bitte ändert daher dringend euer Passwort für das Forum. Solltet ihr das gleiche Passwort auch an anderer Stelle verwenden, ändert es bitte unbedingt an allen Stellen!
conditional form?
- abief
-
Autor
- Offline
- Premium Mitglied
-
- I'm here, there and elsewhere!
- Beiträge: 95
- Thanks: 19
conditional form?
04 Apr. 2018 04:41
Hi,
can somebody provide a sample on how to build a conditional form?
My code:
local function setupForm(formId)
-- load sensors
sensorsAvailable = {}
local available = system.getSensors();
local formSensors={}
local formSensorsIndex=-1
for index,sensor in ipairs(available) do
if(sensor.param == 0 and
(string.sub(sensor.label, 1, 3) == _MUI or
string.sub(sensor.label, 1, 5) == _MEZON)
) then
formSensors[#formSensors+1] = sensor.label
sensorsAvailable[#sensorsAvailable+1] = sensor
if(sensor.id==sensorId ) then
formSensorsIndex=#sensorsAvailable
end
end
end
-- form title
form.setTitle(locale.SetupFormTitle);
-- spacer
form.addSpacer(318,7);
-- sensor (MUI or MEZON)
form.addRow(2);
form.addLabel({label = locale.SetupFormSelectSensorLabel, width = 200});
form. addSelectbox(formSensors, formSensorsIndex, true, sensorChanged);
-- only for MEZON, we add the gearbox ratio
if (sensorMode == _MEZ) then
form.addRow(2);
form.addLabel({label = locale.SetupFormGearBoxValueLabel, width = 200});
form.addIntbox(revolutionsGearboxRatio, 100, 1000, 100, 0, 1, gearboxRatioChanged);
end
-- battery
form.addRow(2);
form.addLabel({label = locale.SetupFormSelectBatteryLabel, width = 200});
form.addIntbox(batteryCapacity, 0, 32000, 0, 0, 10, batteryChanged);
-- spacer
form.addSpacer(318,7);
-- gates
form.addRow(3);
form.addLabel({label = locale.SetupFormRedGateLabel, width = 150});
form.addIntbox(redGate, 0, 100, _REDGATE, 0, 1, redGateChanged);
form.addAudioFilebox(alarmRedGate, alarmRedGateChanged);
form.addRow(3);
form.addLabel({label = locale.SetupFormAmberGateLabel, width = 150});
form.addIntbox(amberGate, 0, 100, _AMBERGATE, 0, 1, amberGateChanged);
form.addAudioFilebox(alarmAmberGate, alarmAmberGateChanged);
form.addRow(3);
form.addLabel({label = locale.SetupFormBlueGateLabel, width = 150});
form.addIntbox(blueGate, 0, 100, _BLUEGATE, 0, 1, blueGateChanged);
form.addAudioFilebox(alarmBlueGate, alarmBlueGateChanged);
collectgarbage();
end
-- print Configuration form
local function printForm(formId)
end
My idea is that if sensorMode is Mezon, then the gearbox ratio parameter shows up, if not, this gearbox ratio is not used.
but I'm not able to make this field to disappear when sensorMode is not mezon.
Suggestions??
Thanks,
can somebody provide a sample on how to build a conditional form?
My code:
local function setupForm(formId)
-- load sensors
sensorsAvailable = {}
local available = system.getSensors();
local formSensors={}
local formSensorsIndex=-1
for index,sensor in ipairs(available) do
if(sensor.param == 0 and
(string.sub(sensor.label, 1, 3) == _MUI or
string.sub(sensor.label, 1, 5) == _MEZON)
) then
formSensors[#formSensors+1] = sensor.label
sensorsAvailable[#sensorsAvailable+1] = sensor
if(sensor.id==sensorId ) then
formSensorsIndex=#sensorsAvailable
end
end
end
-- form title
form.setTitle(locale.SetupFormTitle);
-- spacer
form.addSpacer(318,7);
-- sensor (MUI or MEZON)
form.addRow(2);
form.addLabel({label = locale.SetupFormSelectSensorLabel, width = 200});
form. addSelectbox(formSensors, formSensorsIndex, true, sensorChanged);
-- only for MEZON, we add the gearbox ratio
if (sensorMode == _MEZ) then
form.addRow(2);
form.addLabel({label = locale.SetupFormGearBoxValueLabel, width = 200});
form.addIntbox(revolutionsGearboxRatio, 100, 1000, 100, 0, 1, gearboxRatioChanged);
end
-- battery
form.addRow(2);
form.addLabel({label = locale.SetupFormSelectBatteryLabel, width = 200});
form.addIntbox(batteryCapacity, 0, 32000, 0, 0, 10, batteryChanged);
-- spacer
form.addSpacer(318,7);
-- gates
form.addRow(3);
form.addLabel({label = locale.SetupFormRedGateLabel, width = 150});
form.addIntbox(redGate, 0, 100, _REDGATE, 0, 1, redGateChanged);
form.addAudioFilebox(alarmRedGate, alarmRedGateChanged);
form.addRow(3);
form.addLabel({label = locale.SetupFormAmberGateLabel, width = 150});
form.addIntbox(amberGate, 0, 100, _AMBERGATE, 0, 1, amberGateChanged);
form.addAudioFilebox(alarmAmberGate, alarmAmberGateChanged);
form.addRow(3);
form.addLabel({label = locale.SetupFormBlueGateLabel, width = 150});
form.addIntbox(blueGate, 0, 100, _BLUEGATE, 0, 1, blueGateChanged);
form.addAudioFilebox(alarmBlueGate, alarmBlueGateChanged);
collectgarbage();
end
-- print Configuration form
local function printForm(formId)
end
My idea is that if sensorMode is Mezon, then the gearbox ratio parameter shows up, if not, this gearbox ratio is not used.
but I'm not able to make this field to disappear when sensorMode is not mezon.
Suggestions??
Thanks,
Field ready: Taborca (3.4m), Ocelot (1.6m), Alula (0.6m).
Factory line: FVT-3 (1m), A6M Zero (1.6m), Tiger Moth (2.2m), Grumann Goose (2m) and Beechcraft D18 (1.5m).
Design phase: Szd-20x Wampir II (7.5m), Rutan Quickie (1.6m), both parked.
Dreaming: Weird push-pull called Double Trouble (2.4m)
Factory line: FVT-3 (1m), A6M Zero (1.6m), Tiger Moth (2.2m), Grumann Goose (2m) and Beechcraft D18 (1.5m).
Design phase: Szd-20x Wampir II (7.5m), Rutan Quickie (1.6m), both parked.
Dreaming: Weird push-pull called Double Trouble (2.4m)
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- TeroS
-
- Offline
- Platinum Mitglied
-
- RC-Thoughts
- Beiträge: 527
- Thanks: 370
Re: conditional form?
07 Apr. 2018 09:44 - 07 Apr. 2018 09:45
Please put the code inside code tags so it's more readable.
(Remove spaces before the "]", or more simply, use the <> button in editors buttonline above)
There have been issues with this forums colors with code tag, I hope they will get it fixed sometime...
But an answer, you should look in reinit function and use some if-statements.
Code:
[code type="" ] [/code ]
There have been issues with this forums colors with code tag, I hope they will get it fixed sometime...
But an answer, you should look in reinit function and use some if-statements.
Letzte Änderung: 07 Apr. 2018 09:45 von TeroS.
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- TeroS
-
- Offline
- Platinum Mitglied
-
- RC-Thoughts
- Beiträge: 527
- Thanks: 370
Re: conditional form?
07 Apr. 2018 09:47 - 07 Apr. 2018 09:52
So here's your code:
With a quick look I don't see why that would not work with some adjustment. Where and when do you set the "sensorMode" to "_MEZ"? Have a look in LUA API for "form.reinit"
Code:
local function setupForm(formId)
-- load sensors
sensorsAvailable = {}
local available = system.getSensors();
local formSensors={}
local formSensorsIndex=-1
for index,sensor in ipairs(available) do
if(sensor.param == 0 and
(string.sub(sensor.label, 1, 3) == _MUI or
string.sub(sensor.label, 1, 5) == _MEZON)
) then
formSensors[#formSensors+1] = sensor.label
sensorsAvailable[#sensorsAvailable+1] = sensor
if(sensor.id==sensorId ) then
formSensorsIndex=#sensorsAvailable
end
end
end
-- form title
form.setTitle(locale.SetupFormTitle);
-- spacer
form.addSpacer(318,7);
-- sensor (MUI or MEZON)
form.addRow(2);
form.addLabel({label = locale.SetupFormSelectSensorLabel, width = 200});
form. addSelectbox(formSensors, formSensorsIndex, true, sensorChanged);
-- only for MEZON, we add the gearbox ratio
if (sensorMode == _MEZ) then
form.addRow(2);
form.addLabel({label = locale.SetupFormGearBoxValueLabel, width = 200});
form.addIntbox(revolutionsGearboxRatio, 100, 1000, 100, 0, 1, gearboxRatioChanged);
end
-- battery
form.addRow(2);
form.addLabel({label = locale.SetupFormSelectBatteryLabel, width = 200});
form.addIntbox(batteryCapacity, 0, 32000, 0, 0, 10, batteryChanged);
-- spacer
form.addSpacer(318,7);
-- gates
form.addRow(3);
form.addLabel({label = locale.SetupFormRedGateLabel, width = 150});
form.addIntbox(redGate, 0, 100, _REDGATE, 0, 1, redGateChanged);
form.addAudioFilebox(alarmRedGate, alarmRedGateChanged);
form.addRow(3);
form.addLabel({label = locale.SetupFormAmberGateLabel, width = 150});
form.addIntbox(amberGate, 0, 100, _AMBERGATE, 0, 1, amberGateChanged);
form.addAudioFilebox(alarmAmberGate, alarmAmberGateChanged);
form.addRow(3);
form.addLabel({label = locale.SetupFormBlueGateLabel, width = 150});
form.addIntbox(blueGate, 0, 100, _BLUEGATE, 0, 1, blueGateChanged);
form.addAudioFilebox(alarmBlueGate, alarmBlueGateChanged);
collectgarbage();
end
-- print Configuration form
local function printForm(formId)
end
With a quick look I don't see why that would not work with some adjustment. Where and when do you set the "sensorMode" to "_MEZ"? Have a look in LUA API for "form.reinit"
Letzte Änderung: 07 Apr. 2018 09:52 von TeroS.
Folgende Benutzer bedankten sich: abief
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- abief
-
Autor
- Offline
- Premium Mitglied
-
- I'm here, there and elsewhere!
- Beiträge: 95
- Thanks: 19
Re: conditional form?
07 Apr. 2018 10:17 - 07 Apr. 2018 10:27
Ok, I solved it myself.
I'm not sure if this is the right solution, but it works.
In my case, the reason why I need the form to add a parameter when I use a MEZON sensor, to determine the gearbox setting.
Basically, in the setup form I want to be able to switch from
to
I have a variable, called sensorMode, that determines if the sensor is a MUI or a MEZON. If Mezon is active, there is a revolutions parameter that I need to determine and apply the gearbox reduction in order to obtain the actual propeller revolutions.
first, I added a local variable at the start of the lua code:
second, I slightly change the code in my setup form. so to skip the gearbox field if sensor mode is not MEZON...
now, as this code is present in the setupform function, it's only called once, when we setup the form.
So, I added some code also the the sensorChanged function (that is, the code associated to the change of sensors between MUI and MEZON).
this way I know what was the previous value of sensormode.
Lastly, I add a function to my code, and that is the printform
I change my definition of the setup of the form by adding the proper calls
and I complete the printform function.
this is called as the loop, every 22ms...
the important line is
this line basically respawns the initform code, so the form is effectively regenerated.
hope it helps
I'm not sure if this is the right solution, but it works.
In my case, the reason why I need the form to add a parameter when I use a MEZON sensor, to determine the gearbox setting.
Basically, in the setup form I want to be able to switch from
to
I have a variable, called sensorMode, that determines if the sensor is a MUI or a MEZON. If Mezon is active, there is a revolutions parameter that I need to determine and apply the gearbox reduction in order to obtain the actual propeller revolutions.
first, I added a local variable at the start of the lua code:
Code:
local previousSensorMode = sensorMode; -- to change the form
second, I slightly change the code in my setup form. so to skip the gearbox field if sensor mode is not MEZON...
Code:
-- only for MEZON, we add the gearbox ratio
if (sensorMode == _MEZ) then
form.addRow(2);
form.addLabel({label = locale.SetupFormGearBoxValueLabel, width = 200});
form.addIntbox(revolutionsGearboxRatio, 100, 1000, 100, 2, 1, gearboxRatioChanged);
form.addSpacer(318,7);
end
now, as this code is present in the setupform function, it's only called once, when we setup the form.
So, I added some code also the the sensorChanged function (that is, the code associated to the change of sensors between MUI and MEZON).
Code:
local function sensorChanged(value)
previousSensorMode = sensorMode;
-- some more code here
end
this way I know what was the previous value of sensormode.
Lastly, I add a function to my code, and that is the printform
I change my definition of the setup of the form by adding the proper calls
Code:
system.registerForm(1, MENU_APPS, locale.AppName, setupForm, nil, printForm);
and I complete the printform function.
this is called as the loop, every 22ms...
Code:
-- print Configuration form
local function printForm()
if (sensorMode ~= previousSensorMode) then
previousSensorMode = sensorMode;
form.reinit();
end
end
the important line is
Code:
form.reinit();
this line basically respawns the initform code, so the form is effectively regenerated.
hope it helps
Field ready: Taborca (3.4m), Ocelot (1.6m), Alula (0.6m).
Factory line: FVT-3 (1m), A6M Zero (1.6m), Tiger Moth (2.2m), Grumann Goose (2m) and Beechcraft D18 (1.5m).
Design phase: Szd-20x Wampir II (7.5m), Rutan Quickie (1.6m), both parked.
Dreaming: Weird push-pull called Double Trouble (2.4m)
Factory line: FVT-3 (1m), A6M Zero (1.6m), Tiger Moth (2.2m), Grumann Goose (2m) and Beechcraft D18 (1.5m).
Design phase: Szd-20x Wampir II (7.5m), Rutan Quickie (1.6m), both parked.
Dreaming: Weird push-pull called Double Trouble (2.4m)
Letzte Änderung: 07 Apr. 2018 10:27 von abief.
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- abief
-
Autor
- Offline
- Premium Mitglied
-
- I'm here, there and elsewhere!
- Beiträge: 95
- Thanks: 19
Re: conditional form?
07 Apr. 2018 10:28TeroS wrote: So here's your code:
--
With a quick look I don't see why that would not work with some adjustment. Where and when do you set the "sensorMode" to "_MEZ"? Have a look in LUA API for "form.reinit"
thanks, we arrived to the same conclusion!
Field ready: Taborca (3.4m), Ocelot (1.6m), Alula (0.6m).
Factory line: FVT-3 (1m), A6M Zero (1.6m), Tiger Moth (2.2m), Grumann Goose (2m) and Beechcraft D18 (1.5m).
Design phase: Szd-20x Wampir II (7.5m), Rutan Quickie (1.6m), both parked.
Dreaming: Weird push-pull called Double Trouble (2.4m)
Factory line: FVT-3 (1m), A6M Zero (1.6m), Tiger Moth (2.2m), Grumann Goose (2m) and Beechcraft D18 (1.5m).
Design phase: Szd-20x Wampir II (7.5m), Rutan Quickie (1.6m), both parked.
Dreaming: Weird push-pull called Double Trouble (2.4m)
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
Moderatoren: Thorn, IG-Modellbau
Ladezeit der Seite: 0.547 Sekunden