Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Truncate numerical values #46

Closed
jonestristand opened this issue Jan 3, 2024 · 15 comments
Closed

Truncate numerical values #46

jonestristand opened this issue Jan 3, 2024 · 15 comments

Comments

@jonestristand
Copy link

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

@Fragtality
Copy link
Owner

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

@jonestristand
Copy link
Author

jonestristand commented Jan 4, 2024 via email

@Fragtality
Copy link
Owner

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.

@jonestristand
Copy link
Author

jonestristand commented Jan 4, 2024 via email

@Fragtality
Copy link
Owner

Haha that wasn't the Intention 😅

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

@jonestristand
Copy link
Author

jonestristand commented Jan 5, 2024 via email

@Fragtality
Copy link
Owner

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

@Chpouky
Copy link

Chpouky commented Jan 31, 2024

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

@jonestristand
Copy link
Author

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

@Chpouky
Copy link

Chpouky commented Feb 3, 2024

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

@richardkennedy
Copy link

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.

@Fragtality
Copy link
Owner

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
Copy link
Owner

Closed => Fixed (Value Format or Lua Values)

@richardkennedy
Copy link

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?

@Fragtality
Copy link
Owner

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

Fix will be committed when I've repaired SimConnect 😩

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants