PilotsDeck icon indicating copy to clipboard operation
PilotsDeck copied to clipboard

Truncate numerical values

Open jonestristand opened this issue 1 year ago • 10 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...

jonestristand avatar Jan 03 '24 21:01 jonestristand

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).

Fragtality avatar Jan 04 '24 15:01 Fragtality

FlyWithLua will work and I'll implement with that - thanks! However would be nice if some more numerical manipulation/calculation methods were implemented.

In my case I have a Stream Deck Plug and want to show one digit of the transponder on each dial and use the dials to change the number

On Thu, Jan 4, 2024 at 7:06 AM Fragtality @.***> wrote:

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).

— Reply to this email directly, view it on GitHub https://github.com/Fragtality/PilotsDeck/issues/46#issuecomment-1877246250, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOGK3Y4JXIDWMO65JIZ6OLYM3ANTAVCNFSM6AAAAABBMAHMZSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZXGI2DMMRVGA . You are receiving this because you authored the thread.Message ID: @.***>

jonestristand avatar Jan 04 '24 19:01 jonestristand

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.

Fragtality avatar Jan 04 '24 20:01 Fragtality

Haha hey no need to insult my setup ;-)

I have a folder just for the transponder (ident, Ta/ra, mode c) and all the encoders sitting there unused 😁

On Thu, Jan 4, 2024, 12:38 Fragtality @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/Fragtality/PilotsDeck/issues/46#issuecomment-1877729637, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOGK3YCOB3CTLCYMNHUXO3YM4HMJAVCNFSM6AAAAABBMAHMZSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZXG4ZDSNRTG4 . You are receiving this because you authored the thread.Message ID: @.***>

jonestristand avatar Jan 04 '24 23:01 jonestristand

Haha that wasn't the Intention 😅

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

Fragtality avatar Jan 05 '24 13:01 Fragtality

No worries, all good!

Do you collect profiles anywhere? I've got a fairly comprehensive one for the Q4XP

On Fri, Jan 5, 2024 at 5:18 AM Fragtality @.***> wrote:

Haha that wasn't the Intention 😅

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

— Reply to this email directly, view it on GitHub https://github.com/Fragtality/PilotsDeck/issues/46#issuecomment-1878647676, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABOGK3Y2RXBOZKX2JGQ6GZDYM74SBAVCNFSM6AAAAABBMAHMZSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQNZYGY2DONRXGY . You are receiving this because you authored the thread.Message ID: @.***>

jonestristand avatar Jan 05 '24 19:01 jonestristand

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) 😉

Fragtality avatar Jan 05 '24 19:01 Fragtality

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

Chpouky avatar Jan 31 '24 13:01 Chpouky

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()")

jonestristand avatar Feb 03 '24 07:02 jonestristand

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

Chpouky avatar Feb 03 '24 11:02 Chpouky

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.

richardkennedy avatar May 16 '24 07:05 richardkennedy

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

Fragtality avatar May 30 '24 20:05 Fragtality

Closed => Fixed (Value Format or Lua Values)

Fragtality avatar Jun 03 '24 20:06 Fragtality

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?

richardkennedy avatar Jun 04 '24 14:06 richardkennedy

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

Fix will be committed when I've repaired SimConnect 😩

Fragtality avatar Jun 04 '24 14:06 Fragtality