Private or Global Variables?

For questions about using Classic.

Post » Sun May 06, 2012 9:20 pm

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.



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.blackarcadia2012-05-06 21:23:33
B
5
S
1
G
1
Posts: 9
Reputation: 469

Post » Sun May 06, 2012 10:01 pm

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.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Sun May 06, 2012 10:13 pm

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.
B
5
S
1
G
1
Posts: 9
Reputation: 469


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 7 guests