How to store multiple numerical values in a single number?

tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
edited December 2012 in Working with GS (Mac)
I'm using tables to store user account data but I'm having a hard time finding a way to keep track of the values I need to save. My game has 100 rounds and each round has several values, so a user on round 5 stores its score, time, etc. I have a row for each user and a column for each round, but I need a way to store multiple values (numbers) in a single table cell. For text, I'm using @tshirtbooth's !word1!word2! method but I'm hoping @RThurman or someone else can guide me here:

Is there a way to mathematically notate several values in a single number?

For example, let's say that the player's score is 500 and his time is 28. I'd like to be able to change a table cell value to 500028 where 028 stores the time, and then retrieve it by doing something like floor(500028/1000)=score and (500028%1000)=time.

So that works for two numbers but what if I want to store 3? or 4? What if I stored 5000280609 where 06 and 09 were possible single-digit or maybe two-digit numbers? Is there an existing mathematical system that will do this?

I'm starting to answer my question... it seems like I can use %10, %100, etc., but am I on the right track?

Okay, a separate but related question... I thought of another way to do this if I don't need to store things like a score, but rather just multiple booleans, by adding (or maybe multiplying?) unique values and then checking the final sum/product. For example, if , add 1 to the value; if , add 3 to the value; and then if the value=1 I know only condition 1 is true, if the value=3, I know only condition 2 is true, and if the value=4, I know both conditions are true..... how would I do this with 6 conditions?

Best Answer

  • MarkOnTheIronMarkOnTheIron Posts: 1,447
    edited December 2012 Accepted Answer
    You should be on the right track. I would probably do something like this:

    Example: Score=500 Time=28 Lives=2

    At the end of the round use a change the relative cell value to (game.Score*1000000)+(game.Time*1000)+game.Lives (the result should be 500028002)

    If you want to recover it:
    change the game.Score attribute to floor((table(whereyoustoredthenumber))/1000000)
    change the game.Time attribute to (floor(((table(whereyoustoredthenumber))/1000))%1000
    change the game.Time attribute to (table(whereyoustoredthenumber))%1000

    ()'s may be wrong somewere :)

Answers

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    A quick google of "unique sums" shows that I can use powers of two for the second problem.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    @MarkOnTheIron thanks! Wanted to make sure it was possible.
Sign In or Register to comment.