Fragtality/PilotsDeck

Truncate numerical values

jonestristand opened this issue · 15 comments

It would be very useful to be able to truncate a numerical value, for instance I can retrieve the transponder code from the dataref in xplane, but there's no way I can think of to get just the ones, or just the tens, or just the hundreds digit...

Hmm, that is right. But I can't follow why splitting up a Value would be beneficial at all? I mean what would be the Reasoning behind displaying the Transponder on 4 different Buttons instead of 1?

Have you considered looking into FlyWithLua? You could run some code There that would split up that Number and write it to 4 custom DataRefs (which then can be used like any other DataRef in the Plugin).

Because you want it to be such a waste of Space?

You could also work with an Encoder Stack. Like with the Radio-Action, but in that Case 4 Actions stacked.

Haha that wasn't the Intention 😅

Just wanted to make you aware that you can have it smaller, if you want to 😉

Well apart from my own Profiles (shared here or on fs/xp.to) I've added some User Contributions whom did not want to publish it theirself.

So yeah, I could add it here on GitHub, but it would be way more discoverable/noticeable for others if you publish it on x-plane.to and/or x-plane.org (The Plugin itself is also published there) 😉

Hey jonestristand !

Did you figure out a way to do it without LUA ? I'm trying to do the same thing. Right now I have a setup with 4 encoder stack, but I want the thousands/hundreds/etc to be separate as well, juste for the cool factor and because I have no use for the two remaining dials :p

I use FlyWithLua and this script:

dataref("transponder_code", "sim/cockpit/radios/transponder_code", "readonly")
digits =  create_dataref_table("mysim/cockpit/radios/transponder_digits", "IntArray")

function get_digit(value, digit)
  return math.floor(math.abs(value) / 10 ^ digit) % 10
end

function split_transponder()
  digits[0] = get_digit(transponder_code, 0)
  digits[1] = get_digit(transponder_code, 1)
  digits[2] = get_digit(transponder_code, 2)
  digits[3] = get_digit(transponder_code, 3)
end

do_every_frame("split_transponder()")

Awesome, thank you ! I was not familiar with LUA, didn't know it was so easy to read and understand :o

Being able to truncate values would be useful in cases where someone doesn't have a registered/paid version of FSUIPC7 which is required to use LUA scripts. It's lazy I know, but there's a potential use case.

Please test the current Development Build: https://github.com/Fragtality/PilotsDeck/blob/master/Install-PilotsDeck-latest.exe

It added Support for truncating Values as part of the "Format" Option - or more specifically: being able to get the Substring of the Value. Things to Note:

  • Syntax is: start..length - beware that the start Index is zero-based: the first Character is at Index 0
  • It is mutual Exclusive with the Text Format (%s) - you can either do a Text-Format or get the Substring
  • That also means it shares the same Behavior: it is applied after everything else (Scale, Round/Fraction)
  • When the defined Substring is illegal (i.e. out of range) it will return the complete Value

Closed => Fixed (Value Format or Lua Values)

I've created a display value button with an address of (A:TRANSPONDER CODE:1, Number) and a format of 3..1

With the sim transponder set to 0123, I would have expected the output to be 3, but it's 123?

Yeah, typical off-by-one Error 🤦‍♂️

Fix will be committed when I've repaired SimConnect 😩