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!
Default Wert für Schalterbelegung in LUA
- davidmcq137
- Offline
- Senior Mitglied
-
- Beiträge: 79
- Thanks: 87
Re: Default Wert für Schalterbelegung in LUA
19 Dez. 2022 15:22Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- dit71
-
- Offline
- Elite Mitglied
-
- Beiträge: 160
- Thanks: 85
Re: Default Wert für Schalterbelegung in LUA
19 Dez. 2022 16:00The difficult problem was to find the correct activeon value during selecting the switch.
Dieter
TStatus App: github.com/ribid1/TStatus
Notizbuch App: github.com/ribid1/Notebook
3D_Modelle: www.printables.com/@dit71_651800/models
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- davidmcq137
- Offline
- Senior Mitglied
-
- Beiträge: 79
- Thanks: 87
Re: Default Wert für Schalterbelegung in LUA
19 Dez. 2022 16:201) as far as any of us knows, it is not possible to set a default for an _actual_ switchitem (the type returned by form.addInputbox())
2) You cannot serialize an actual switchitem .. any switchitem userdata in a call to json.encode() is an error (I checked again). Of course, Jeti does do a special case for pLoad and pSave for handling the userdata "real" switchitems.
So, if you want to solve problem 1 or problem 2 you need another approach. The approach I believe you are using, and I am also using in my maps app, is the create some "soft switchitem" data .. basically the table needed for system.createSwitch(). This works fine and solves problem 1 and 2.
But .. it means you cannot ALSO use form.addInputbox which is the familiar process for pilots. If you try to mix the two approaches, and let the pilot define a switch with form.addInputbox, then extract the "soft switchitem" data using system.getSwitchInfo() you run into the +/-1 problem. In summary ... addInputbox returns the +1 direction as whatever direction the pilot flipped the switch . .which could be up or down or middle .. and there is no way to know what that direction was. So while you can call getSwitchInfo, you won't know the active direction.
I've tried very hard to solve that and I cannot. If you are solving this in your app please show me where .. I did not see it .. I tried!
So .. you can go "native Jeti" and just use pSave and pCall as the persistence model and have no way to default .. and a weak persistence model .. or .. you can use a json file as the persistence model, and create and serialize your own "soft switchitems" and solve both .. but you will end up with some menuapproach to assign the switches which will work fine but won't be the familiar addInputbox user interface.
What do you think?
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- dit71
-
- Offline
- Elite Mitglied
-
- Beiträge: 160
- Thanks: 85
Re: Default Wert für Schalterbelegung in LUA
19 Dez. 2022 17:30
using system.getSwitchInfo() you run into the +/-1 problem. In summary ... addInputbox returns the +1 direction as whatever direction the pilot flipped the switch . .which could be up or down or middle .. and there is no way to know what that direction was. So while you can call getSwitchInfo, you won't know the active direction.
Here is the solution:
local function switchChanged(switchName, value)
local Invert = 1.0
local swInfo = system.getSwitchInfo(value)
local swTyp = string.sub(swInfo.label,1,1)
if swInfo.assigned then
if string.sub(swInfo.mode,-1,-1) == "I" then Invert = -1.0 end
if swInfo.value == Invert or swTyp == "L" or swTyp =="M" then
vars.switches[switchName] = value
system.pSave(switchName, value)
form.setButton(1, "save",ENABLED)
vars.changedConfig = 1
vars.switchInfo[switchName] = {}
vars.switchInfo[switchName].name = swInfo.label
vars.switchInfo[switchName].mode = swInfo.mode
if swTyp == "L" or swTyp =="M" then
vars.switchInfo[switchName].activeOn = 0
else
vars.switchInfo[switchName].activeOn = system.getInputs(string.upper(swInfo.label))
end
else
system.messageBox(vars.trans.switchError, 3)
if vars.switches[switchName] then
form.setValue(switch[switchName],vars.switches[switchName])
else
form.setValue(switch[switchName],nil)
end
end
else
if vars.switchInfo[switchName] then
vars.switches[switchName] = nil
vars.switchInfo[switchName] = nil
form.setButton(1, "save",ENABLED)
system.pSave(switchName, nil)
vars.changedConfig = 1
end
end
collectgarbage()
end
It is not true that you always get +1 from the addinputbox, you get -1 if he moved the switch two times or he choosed inverted. If he choose "inverted" everything is okay, you got the information. If you get -1 and he didn't invert then he moved the stick twice, I don't allow that, because if you have a 3-position switch you don't know in which position the switch is now, with a 2-position switch you woulld be fine - of course it can only be on the other side.
With getswitchinfo you get if he has moved the stick or not, and you can be sure if not it is now on the position he has selected. Finally all you have to do is system.getinputs to get if it is -1, 0, or +1 Then you have everything you need and can restore the switch.
I hope it is unterstandible how it works.
Dieter
TStatus App: github.com/ribid1/TStatus
Notizbuch App: github.com/ribid1/Notebook
3D_Modelle: www.printables.com/@dit71_651800/models
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- dit71
-
- Offline
- Elite Mitglied
-
- Beiträge: 160
- Thanks: 85
Re: Default Wert für Schalterbelegung in LUA
19 Dez. 2022 17:34Dieter
TStatus App: github.com/ribid1/TStatus
Notizbuch App: github.com/ribid1/Notebook
3D_Modelle: www.printables.com/@dit71_651800/models
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- davidmcq137
- Offline
- Senior Mitglied
-
- Beiträge: 79
- Thanks: 87
Re: Default Wert für Schalterbelegung in LUA
19 Dez. 2022 17:59On the "moved the switch twice" .. how do you "not allow it"? You just document it as "don't do that"?
Bitte Anmelden oder Registrieren um der Konversation beizutreten.