How do I store set of values?

0 favourites
  • 5 posts
From the Asset Store
A system for storing and processing information online
  • Hi,

    I need help in storing three set of values like an User A scores X in Level X, scores Y in Level Y and so on and I would like do the same for multiple users in the same application.

    Example

    - User A

    - Level 1 Score - 10

    - level 2 Score - 20

    - Level 3 Score - 30

    - User B

    - Level 1 Score - 5

    - level 2 Score - 15

    - Level 3 Score - 25

    So when I check the details of User A, I should get all their details. Similarly, we User B. How do I do this? Will array work?

    Can anyone help?

    Thanks in advance

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yes, you can use 2D array. Set array width to the number of users, height to the number of values you need to store. Note that indices in arrays are 0-based. For example, if you need to set first user name to "John", do:

    Array Set at X=0, Y=0, Value="John"

    To set level 10 score for player number 5:

    Array Set at X=4, Y=10, Value=score

    etc.

    .

    You can save the entire array in Local Storage if needed using Array.AsJSON, and load it back using "Array set from JSON".

  • dop2000 Wow, that's so cool thanks for the tip. I will implement it.

    BTW how do I search for values in array?

  • you can use IndexOf to search the X axis. If the data you are looking for isn't in the first column then you have to manually loop through each element of the array

    or use a second array as an index back to the first array - copy all the data from the column you want to search into the first column of the index array, the second column is set to the row the data came from in the first array. then you can sort or search the index array and link back to the main array...

  • AllanR This works. Thanks alot for your valuable inputs. :D

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)