Number Encoding (Put lots of numbers into 1)

VmlwebVmlweb Member Posts: 427
edited November -1 in Working with GS (Mac)
Hey,

I've just finished making a maths formula that might be useful for a lot of you.
Basically it lets you store multiple numbers in 1 integer.
This encoded number will have a specified number of positions, each of these positions would contain a number as well.
All you do with these formulas is fill in the letters with the number to fit:

============================== Formulas =========================================

Adding To The Positions=

x + z * ( y ^ n )

x = Encoded Number To Add To
z = Amount To Add To The Position
y = Max Size Of The Position Numbers (eg. for a max of 10 in a position y would be 11)
n = Position To Add To

Extracting A Position=

floor ( x / y ^ n) % y

x = Encoded Number To Extract From
y = Max Size Of The Position Numbers (eg. for a max of 10 in a position y would be 11)
n = Position To Extract

================================= FAQ ===========================================

Where would I use this?
If you have high-scores for instance instead of having a separate integers for every single high score this could hold all of them.

Is there a limit to the positions?
Yes, there is a limit to how many positions you can have which is limited by y which is the max size you can have.
If y is 3 which means each position would be 1 or 2, then you would be able to fit much more positions in than if y was equal to 20

What happens if a position value is bigger than the max size I put?
It will extract as 0

=================================================================================

Hope this helps you,
If you have any questions please ask.

Thanks,
Vmlweb

Comments

  • ORBZORBZ Member Posts: 1,304
    Nice :) I'm going to try this out!
  • rebumprebump Member Posts: 1,058
    Wouldn't there need to be a max value for a high score to go along with the limits in the number of positions available for high scores (which I assume is "Y" in your work above)?

    I don't really see this working without further constraints for the high score values and/or I'm just misinterpreting your descriptions of your variables above.

    When you say "position" above, I intepret it as a position on the high score leaderboard but further down in your FAQ, it almost reads as if position a high score value.

    Confused. :-|
  • VmlwebVmlweb Member Posts: 427
    Think of the encoded number like this

    | Position0 | Position1 | Position2 | Position3 |

    Those positions can be changed individually.
    Say if I use the Add To Position formula and replace n=2 and z=4
    That would change to

    | Position0 | Position1 | 4 | Position3 |

    I haven't wrote this down properly it's just to show you cause If you haven't added anything to a position it's value is 0.
    Really the above would be

    | 0 | 0 | 4 | 0
  • VmlwebVmlweb Member Posts: 427
    This is very hard to understand.
    If your still struggling I'll make an example for you
  • rebumprebump Member Posts: 1,058
    I think I understand how it is supposed to work but I think each position/slot will have a max number you can put in it (which you have not defined).

    However, maybe when you say "If you have high-scores for instance..." you mean a high score per level as opposed to a high score list for a single level!?

    So in your second post, you give the starting "state" of your high score integer as:

    `| P0 | P1 | P2 | P3 |`

    which you say really looks like:

    `| 0 | 0 | 0 | 0 |`

    Then you add:

    "Say if I use the Add To Position formula and replace n=2 and z=4"

    To me, that sounds like you want to place the high score value of "4" in the third high score slot, i.e.:

    `
    High Score 1 - 0
    High Score 2 - 0
    High Score 3 - 4
    High Score 4 - 0
    `
    which you represent as:

    `| 0 | 0 | 4 | 0 |`

    (and technically, doesn't make sense, since the high score should go in the first slot if the first slot is still zero but let's ignore that since you are just demonstrating)

    So if your current "state" is now:

    `| 0 | 0 | 4 | 0 |`

    And you want to add high score "3" to the 4th high score position so it looks like:

    `| 0 | 0 | 4 | 3 |`

    I assume X would equal "4" in your equation as you proceed to add the "3" into it.

    Maybe your equations work for these small number examples but what if you have this leaderboard you want to store (with a max high score of say "9999"):

    `
    High Score Position Score
    1 4,321
    2 3,222
    3 2,999
    4 1,000
    5 1,000
    6 570
    7 0
    8 0
    9 0
    10 0
    `
    I see your formulas fall apart if my math was sound.

    So either there are limits to the value stored in each position or my interpretation of your system is incorrect.

    Not trying to be difficult or a nay-sayer. Just want to understand its usage and limitations as it sounds like a neat system to employ in a game!
  • VmlwebVmlweb Member Posts: 427
    The numbers begin at 0
    So

    | P0 | P1 | P2 | P3 | P4 |

    to add to the first position you need n=0
    for the last position it's n=4

    I'll start making an example and upload it
  • rebumprebump Member Posts: 1,058
    Yeah, please do, I'd love to use this.

    If you can, show it encoding:

    `
    High Score Position Score
    1 4,321
    2 3,222
    3 2,999
    4 1,000
    5 1,000
    6 570
    7 0
    8 0
    9 0
    10 0
    `
  • VmlwebVmlweb Member Posts: 427
    Oh I'm sorry I've got some of the maths wrong.
    I'll repost a new topic in a minute with the example.
  • ORBZORBZ Member Posts: 1,304
    keep in mind Vmlweb that eventually GS creators will get around to giving us arrays and structs making the encoding no longer essential. Until then though, this is great work :)
  • quantumsheepquantumsheep Member Posts: 8,188
    You lost me at 'Maths formula' ;)

    QS

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

Sign In or Register to comment.