Default Wert für Schalterbelegung in LUA
- davidmcq137
-
Offline
- Senior Mitglied
-
- Beiträge: 79
- Dank erhalten: 86
thanks. I will write up a little test program that hopefully will isolate the interesting parts and make this clear.
von davidmcq137
Folgende Benutzer bedankten sich: sierra_uniform
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- dit71
-
Offline
- Elite Mitglied
-
- Beiträge: 160
- Dank erhalten: 85
You can use use the createswitch command also for default switchitems, you know the name and you just have to figure out once which is the activeone value and the modifiers value, then if you like you can define the switches hard coded in the app. Otherwise I don't unterstand the problem.
The difficult problem was to find the correct activeon value during selecting the switch.
Dieter
The difficult problem was to find the correct activeon value during selecting the switch.
Dieter
dbdis App:
github.com/ribid1/dbdis
TStatus App: github.com/ribid1/TStatus
Notizbuch App: github.com/ribid1/Notebook
3D_Modelle: www.printables.com/@dit71_651800/models
TStatus App: github.com/ribid1/TStatus
Notizbuch App: github.com/ribid1/Notebook
3D_Modelle: www.printables.com/@dit71_651800/models
von dit71
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- davidmcq137
-
Offline
- Senior Mitglied
-
- Beiträge: 79
- Dank erhalten: 86
OK .. let me summarize what is going on as I see it .. let's see if we agree or not...
1) 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?
1) 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?
von davidmcq137
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- dit71
-
Offline
- Elite Mitglied
-
- Beiträge: 160
- Dank erhalten: 85
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
dbdis App:
github.com/ribid1/dbdis
TStatus App: github.com/ribid1/TStatus
Notizbuch App: github.com/ribid1/Notebook
3D_Modelle: www.printables.com/@dit71_651800/models
TStatus App: github.com/ribid1/TStatus
Notizbuch App: github.com/ribid1/Notebook
3D_Modelle: www.printables.com/@dit71_651800/models
von dit71
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- dit71
-
Offline
- Elite Mitglied
-
- Beiträge: 160
- Dank erhalten: 85
Sorry the format of the code is gone, thats hard to read, but you will find it in the form.lua
Dieter
Dieter
dbdis App:
github.com/ribid1/dbdis
TStatus App: github.com/ribid1/TStatus
Notizbuch App: github.com/ribid1/Notebook
3D_Modelle: www.printables.com/@dit71_651800/models
TStatus App: github.com/ribid1/TStatus
Notizbuch App: github.com/ribid1/Notebook
3D_Modelle: www.printables.com/@dit71_651800/models
von dit71
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
- davidmcq137
-
Offline
- Senior Mitglied
-
- Beiträge: 79
- Dank erhalten: 86
I'll give it a try, thanks! I guess you had the solution all along and I did not see it.
On the "moved the switch twice" .. how do you "not allow it"? You just document it as "don't do that"?
On the "moved the switch twice" .. how do you "not allow it"? You just document it as "don't do that"?
von davidmcq137
Bitte Anmelden oder Registrieren um der Konversation beizutreten.
Moderatoren: Thorn, IG-Modellbau
Ladezeit der Seite: 1.074 Sekunden