How do I set a WebStorage.LocalValue name to a variable name

0 favourites
  • 6 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • What I have:

    A text box where the player will input its ID.

    What I need:

    A way to store that player score based on its ID.

    e.g. >> ID.Text = Logan77 | Score = 100

    WebStorage.LocalValue(ID.Text+"_Score")

    will turn into WebStorage.LocalValue("Logan77_Score")

    then when needed, store Logan's current score to his created WebStorage key.

    Maybe a better way to ask it would be: Is it possible to create a variable name based on another variable value? Or even: How can I store data per UserID?

    I've experience with languages like C#, JS/jQuery, LUA, Python, F#, etc, so I think that something like this can be done with JSON, but how I started with Construct 2 today, I don't have a clue about what to do here

  • You might be able to store information in a Dictionary object or Array, then save it as JSON to the webstorage. Then you can load it from the stored JSON data

  • Yeah, if I could save a JSON file with the UserID as its name (e.g. Logan.JSON) and load test if it exists and then load it or create it depending on the result, that would be easy.

  • When you save stuff you have to name it. You can just put a string inside the name. Something like "Save_File_" & username

    I've made a profile system where I used a number instead to differentiate a number of save slots in this way.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Here's what I would do, others might disagree.

    If the ID text box will always be on the screen, you can use Set local key ID.Text & "_Score"

    If the text box will not be there when a score is submitted, you will have to save the name to a variable, maybe called CurrentPlayerName. So you would set CurrentPlayerName = ID.Text.

    And then when the time came to save the score, you would do the action: Set local key CurrentPlayerName & "_Score"

    Later you could retrieve it by the action: Set (some variable or text) to Webstorage.LocalValue(CurrentPlayerName & "_Score")

  • Great ideas guys! Many thanks!

    Gonna experiment with them and see what I can do

    Thanks for your time!

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