Private or Global Variables?

This forum is currently in read-only mode.
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've been wondering if there's a Private Variable workaround for this problem I'm having or if I should even be worrying about this at all.

    <img src="http://dl.dropbox.com/u/5678259/8%20Bit%20Bastards/tumblr_m22qzgA5dQ1qcf1hio1_1280.png" border="0" />

    GLOBAL

    The player character in my project has a bunch of variables on the HUD that's currently set to global (HP, SP, lvl, name, profile, cash, rsc, rscCount, assist, assistState & buff), I hear using too many global variables can slow down a game though (not sure if this is true as I have yet to see it happen).

    If I change layouts when the character collides with the layout boundary or a warp hotspot, the variables reflect any changes that happened in the previous layout.

    PRIVATE

    If I choose to use private variables instead, when the character moves to another layout, the variables reset to their defaults because the character object isn't marked as global.

    When the character is marked as global though, on layout change, another instance of the character is spawned that causes conflicts with the "Center view" attribute. Destroying the character object at the end of the layout resets the variables too.

    If global variables don't slow down the game (again, I'm not sure of this being true) then this wouldn't be something I'd bother avoiding but if it does then I'd like to know any solutions for using private variables whose changes stay throughout layout changes otherwise I might just end up with way too many global variables which include unlocks, assist delays, weather, day phase, combo count and the basic variables (HP, SP, etc.) for about 5 separate characters due to possible multiplayer that I'd like to implement.

    Many thanks for any help offered.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Id suggest getting rid of global objects, and use global variables.

    If you make an event sheet include that sets the private variables to the global variables, and put that include in the layouts you need that to happen, its much easier to deal with.

  • Much thanks, newt! I'll give that a shot and yeah, I found it hellish dealing with too many global objects that one time I tried making my environments with a bunch of individual objects set to global.

    Global variables it is. <img src="smileys/smiley1.gif" border="0" align="middle" />

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