How do I Save all Global Variables to Local Storage?

0 favourites
  • 9 posts
From the Asset Store
Globals 2.0
$3.99 USD
Globals 2.0 stores and group variables. You can also load and save data (variables) from/to JSON files.
  • I have game settings and I'm just trying to make it to where they don't need to be set every time you load the game. So I was just hoping I could with one event and one action, just store everything needed.

    Tagged:

  • kibaga.org/c3-example/file_uploads/index.php

    In this example, the state of the sound is preserved.

    You can also save any of your variables.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • kibaga.org/c3-example/file_uploads/index.php

    In this example, the state of the sound is preserved.

    You can also save any of your variables.

    Not quite what I'm looking for, I understand saving one thing at a time, but is there a way to save all of them in one action and then recall them all in one actions, because I need multiple variables and I just don't want this to look super long on my event sheet.

    Would doing something like Set Key: "Variables" Value: Variable 1 | Variable 2 | Variable 3

    Then whenever I load the Key "Variables" somehow set all the Variables to the values it stored? Is there anyways to do that that I'm not thinking of, or do I genuinely have to do this one variable at a time?

  • Put your global variables in a dictionary and save the dictionary. You are probably better off accessing global variables through function calls to a dictionary since it won't cloud up the global space.

    Just a suggestion.

    yours

    winkr7

  • I also recommend a dictionary in this case. You can then save it with Dictionary.asJSON

    Would doing something like Set Key: "Variables" Value: Variable 1 | Variable 2 | Variable 3

    This works but isn't as clean. You'd do

    variable1 & "|" & variable2 & "|" & variable3
    

    And when you get them back you'd

    Set variable 1 to tokenat(valuefromstorage, 0, "|")
    Set variable 2 to tokenat(valuefromstorage, 1, "|")
    Set variable 3 to tokenat(valuefromstorage, 2, "|")
    
  • howtoconstructdemos.com/easily-save-multiple-values-in-local-storage

    Okay, so yes, save and load each of them one at a time.

  • I also recommend a dictionary in this case. You can then save it with Dictionary.asJSON

    > Would doing something like Set Key: "Variables" Value: Variable 1 | Variable 2 | Variable 3

    This works but isn't as clean. You'd do

    > variable1 & "|" & variable2 & "|" & variable3
    

    And when you get them back you'd

    > Set variable 1 to tokenat(valuefromstorage, 0, "|")
    Set variable 2 to tokenat(valuefromstorage, 1, "|")
    Set variable 3 to tokenat(valuefromstorage, 2, "|")
    

    ...wouldn't this be how you save them with a dictionary though? like it's either this or doing each of them one at a time right?

    Like if I don't do it that first way then wouldn't it be:

    On Button Click:

    Set Key: "Variable 1" Value: Variable 1

    Set Key: "Variable 2" Value: Variable 2

    ...and so on

  • > kibaga.org/c3-example/file_uploads/index.php

    > In this example, the state of the sound is preserved.

    > You can also save any of your variables.

    Not quite what I'm looking for, I understand saving one thing at a time, but is there a way to save all of them in one action and then recall them all in one actions, because I need multiple variables and I just don't want this to look super long on my event sheet.

    Would doing something like Set Key: "Variables" Value: Variable 1 | Variable 2 | Variable 3

    Then whenever I load the Key "Variables" somehow set all the Variables to the values it stored? Is there anyways to do that that I'm not thinking of, or do I genuinely have to do this one variable at a time?

    You can create a separate event sheet for functions and place the "Save_Global_Variable" function on it

    And then just call it everywhere in the code, it will look more elegant.

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