Jump to content
The simFlight Network Forums

LVar Offset Conditionals on Button and Setting Race Condition


pilotjohn

Recommended Posts

I hate to come with more support requests, but here it goes... 🙂

I'm trying to use an LVar to toggle a switch in the Kodiak (XMLVAR_AUX_Bus_ON to either 0 or 1).

I'm moving this into an offset, and then using conditionals to set them based on their current state.

[LvarOffsets]
1=L:XMLVAR_AUX_Bus_ON=UB0xA000

[Buttons]
10=BA000=0 P64,8,Cx0100A000,x01 	-{offset byte set, offset A000}-
11=BA000>0 P64,8,Cx0100A000,x00 	-{offset byte set, offset A000}-

The challenge seems to be that after #10, when A000 is set to 1, #11 tests TRUE and immediately sets it back to 0.

Here it is turning it off (from an on state):

  1206718 Monitor IPC:A000 (U8) = 1
  1210562 Button changed: bRef=0, Joy=64, Btn=8, Pressed
  1210562 [Buttons.Kodiak 100 cargo pod, Factory paint A4] 10=BA000=0 P64,8,Cx0100A000,x01
  1210562 .... Offset check: xA000/1 = 0? (1), Result = FALSE
  1210562 [Buttons.Kodiak 100 cargo pod, Factory paint A4] 11=BA000>0 P64,8,Cx0100A000,x00
  1210562 .... Offset check: xA000/1 > 0? (1), Result = TRUE
  1210562 IPC Offsets Control: Ctrl=x0100, Length=1, Offset=A000, Param=x0
  1210562 Monitor IPC:A000 (U8) = 0
  1210687 Button changed: bRef=0, Joy=64, Btn=8, Released

And here it is trying to turn it back on (when it's in an off state):

  1298265 Button changed: bRef=0, Joy=64, Btn=8, Pressed
  1298265 [Buttons.Kodiak 100 cargo pod, Factory paint A4] 10=BA000=0 P64,8,Cx0100A000,x01
  1298265 .... Offset check: xA000/1 = 0? (0), Result = TRUE
  1298265 IPC Offsets Control: Ctrl=x0100, Length=1, Offset=A000, Param=x1
  1298265 [Buttons.Kodiak 100 cargo pod, Factory paint A4] 11=BA000>0 P64,8,Cx0100A000,x00
  1298265 .... Offset check: xA000/1 > 0? (1), Result = TRUE
  1298265 IPC Offsets Control: Ctrl=x0100, Length=1, Offset=A000, Param=x0
  1298296 Button changed: bRef=0, Joy=64, Btn=8, Released

Notice that both conditions are true, which shouldn't be (per a previous thread).

Here's a previous post where I ran into this, but that was resolved through some other means (e.g. an update to variable offsets).

Any thoughts? There are some other LVars that are multi-state that I'd like to do this for as well, while keeping the sim state together with the button action (which is why button flags don't work).

Thanks,

John

 

Link to comment
Share on other sites

10 hours ago, pilotjohn said:

Notice that both conditions are true, which shouldn't be (per a previous thread).

Button assignments are processed sequentially, in order. When assigned 11 is processed, if 10 has already been processed and the value in offset A000 changed from 0 to 1, then the condition for 11 would then be true and so processed.

10 hours ago, pilotjohn said:

Here's a previous post where I ran into this, but that was resolved through some other means (e.g. an update to variable offsets).

That case is different as it was sending a control, which requires a round trip to the server, and we also never got to the reason why it wasn't working as expected. In this case, it is obvious  as the offset is directly changed by the first assignment, so the condition will be true when the 2nd assignment is processed.

John

Link to comment
Share on other sites

What you could do is just use the offsets for reading the lvar state and change them using calculator code / presets. So, you would define a preset (in your myevents.txt file):
     Aux_Bus#$Param (>L:XMLVAR_AUX_Bus_ON)
And then assign to that preset (with parameters 1 and 0 respectively) instead of the Offset Byte Set control.

John

Link to comment
Share on other sites

I will also look into this further...I think offset writes to user-defined offsets are automatically copied to the read area, which is why the 2nd condition would be true. For offsets that have lvars added to them, there should be no copy and the read offset area should only be updated when the new value is received from the FS.

Link to comment
Share on other sites

5 hours ago, John Dowson said:

I will also look into this further...I think offset writes to user-defined offsets are automatically copied to the read area, which is why the 2nd condition would be true. For offsets that have lvars added to them, there should be no copy and the read offset area should only be updated when the new value is received from the FS.

Thanks... this would be great if it could act more "atomic". Please let me know if you need to me test.

5 hours ago, John Dowson said:

What you could do is just use the offsets for reading the lvar state and change them using calculator code / presets. So, you would define a preset (in your myevents.txt file):
     Aux_Bus#$Param (>L:XMLVAR_AUX_Bus_ON)
And then assign to that preset (with parameters 1 and 0 respectively) instead of the Offset Byte Set control.

I see, since this doesn't update the offset area, it would have to come from the sim, which shouldn't happen while button processing is happening? I'll take a look at this functionality (haven't used it in the past). So I have to have both the offset mechanism to read the state and use it in the conditional, and the macro to execute the change,

Link to comment
Share on other sites

15 minutes ago, pilotjohn said:

I see, since this doesn't update the offset area, it would have to come from the sim, which shouldn't happen while button processing is happening?

correct.

16 minutes ago, pilotjohn said:

So I have to have both the offset mechanism to read the state and use it in the conditional, and the macro to execute the change,

If by macro you mean preset, then also correct.

John

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.