Best way to store variables?

0 favourites
  • 3 posts
From the Asset Store
Best car suspension with spring effect and very cool terrain generation.
  • In my game, changing layouts happens frequently, and I need to find the best way to store variables so they stay consistent between layouts. Say I collect an item in layout 1, then switch to layout 2, and back to layout 1, I want the variable to hold its value.

    I'm only really familiar with global variables, I haven't had any experience with Instance vars, or local storage, which might be better solutions.

    Any info is appreciated!!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Global variables will store values when you switch between layouts, unless you perform "Reset global variables" action.

    If you need to reset most global variables, but want to keep some values, here are the ways you can do it:

    • store values in an array or dictionary
    • you can make a static local variable in an event group. Static local variables are not reset, but you can only access them from within the group.
    • you can create an instance variable on a global object (array for example), or create a dummy object (empty sprite) and set it as global
    • save in Local Storage
  • Thank you for the info!!

    I also remember global vars not resetting from changing layouts, but that wasn't this case.

    Hopped in the Event sheet and found 1 hidden "reset global variable" event, wish I would have remembered putting that there, I can sleep tonight!

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