How do you store your in-game values?

  • Hello!

    So far I've been using multiple objects OUTSIDE the game screen with local variables to store my in-game values in. I found that way to be quite clear for me, even when exiting a project and coming back months later.

    So basically I do:

    Object "playerStats" contains things like: "health", "speed", "currentWeapon" etc.

    Object "weaponStats" contains things like: "name", "damage", "bulletSpeed", "range" etc.

    When the player picks a certain weapon with name x, the stats are set in that weaponStats object.

    Those objects obviously are in a layer (usually my HUD layer) that is gloal.

    I tried solving this via Arrays, but found it overly complicating to always look up which value is meant with a certain X and Y. Dictionaries are more clear on that side but they lack the dimensions that arrays have.

    An array could contain all weapons on the X position and their stats on Y. WIth dictionaries I would still need a global variable for example to solve this.

    What do you use to store your values? Is the method I use any good perfomance wise, or should I rather use something else?

  • Instance variables have a number of advantages over global variables, there is actually a plugin for that, take a look:

    construct.net/en/forum/extending-construct-2/addons-29/plugin-globals-120736

    .

    You don't have to use a sprite object on a global layer. You can use a dictionary or an array (they are set as Global by default), and define instance variables on them! For example, with PlayerStats array you can store some data in the array itself, plus you can have "health" and "speed" instance variables for easy access - for example "Set PlayerStats health to 100"

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • dop2000

    I try to have less than 10 global variables in my projects and leave them only for somem major stats. (Though I could definitely avoid that, too)

    Oh yeah, I didn't try to give my dictionary all the variables instead! I always used Objects, since I can just give all of them a different colored square, thus making it super easy to find them in the event sheet.

    I might try out your version, thank you!

  • Arrays - several if a large one would be to complex. This comes in handy if you want to do local savegames (array to json/ajax and vice versa) or if you want to replace texts for different languages. CSV via ajax to array works quite well. It's hard to set it up the first time, but your later projects will benefit greatly from that.

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