playMaker

Author Topic: Safe to use large amount of globals?  (Read 2068 times)

Krileon

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Safe to use large amount of globals?
« on: February 02, 2013, 05:53:06 PM »
I have many variables that need to be accessed from 3-4 different FSMs. Is it safe to use a lot of global variables? As Is I've about 12 and will need probably 5 more. Just want to make sure this is acceptable practice before moving forward. Performance seams perfectly fine so doesn't seam to hurt there.

nick_h82

  • Playmaker Newbie
  • *
  • Posts: 36
    • View Profile
Re: Safe to use large amount of globals?
« Reply #1 on: February 04, 2013, 01:04:53 AM »
I'd be interested to know from a more technical standpoint as well- I've been publishing test builds of a physics-based game to my 3GS, with 12 global variables, and it seems to run ok.

The internal profiler suggests I'm getting around 32 FPS without much in the way of other optimisations. I briefly stress-tested by switching less essential actions to local variables and the difference wasn't noticeable, so I'd say go for it.

Krileon

  • Full Member
  • ***
  • Posts: 107
    • View Profile
Re: Safe to use large amount of globals?
« Reply #2 on: February 04, 2013, 06:51:12 AM »
Yeah, seams to be my same conclusion. Makes things much easier when those variables need to be accessed from multiple FSMs, which is the point of global variables, lol.

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2488
  • Yup.
    • View Profile
    • Cleverous
Re: Safe to use large amount of globals?
« Reply #3 on: February 04, 2013, 07:31:26 AM »
I have like 30+ and will be adding more. As far as I can tell it isn't an issue... Why would it be?

Andrew_Raphael_Lukasik

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • my twitter @andrewlukasik
Re: Safe to use large amount of globals?
« Reply #4 on: February 04, 2013, 01:06:20 PM »
(tip: when using large number of variables or events, use "/" in their names to segregate them into categories. This helps A LOT)


Edit:
Quote
If you name your global events or variables using "/" for example:

"runtime registry / Players / local Player 0"
"runtime registry / Players / local Player 0 / health"
"runtime registry / Players / local Player 2 / selected weapon"
"runtime registry / MainCamera"
"game state / is paused"
etc.

Then selecting those in Actions' fields will be much convenient because they will be segregated in nice menu. (As far as I tested it works with Variables, Events, Tags and Layers!)
« Last Edit: February 05, 2013, 04:14:15 AM by Andrew_Raphael_Lukasik »

dasbin

  • Junior Playmaker
  • **
  • Posts: 92
    • View Profile
Re: Safe to use large amount of globals?
« Reply #5 on: February 04, 2013, 02:11:45 PM »
I have a few hundred and it works OK. The resulting performance issues are in the editor, not the game. The global variable browser is very slow, and drop-down boxes in actions are a bit slow.

escpodgames

  • Hero Member
  • *****
  • Posts: 677
    • View Profile
    • Assets
Re: Safe to use large amount of globals?
« Reply #6 on: February 04, 2013, 05:59:03 PM »
(tip: when using large number of variables or events, use "/" in their names to segregate them into categories. This helps A LOT)

Can't get this to work, could you explain what you mean by "use "/" in their names to segregate them into categories"

Cheers
Andrew

Andrew_Raphael_Lukasik

  • Full Member
  • ***
  • Posts: 134
    • View Profile
    • my twitter @andrewlukasik
Re: Safe to use large amount of globals?
« Reply #7 on: February 05, 2013, 04:13:22 AM »
Hi @LampRabbit
If you name your global events or variables using "/" for example:

"runtime registry / Players / local Player 0"
"runtime registry / Players / local Player 0 / health"
"runtime registry / Players / local Player 2 / selected weapon"
"runtime registry / MainCamera"
"game state / is paused"
etc.

Then selecting those in Actions' fields will be much convenient because they will be segregated in nice menu. (As far as I tested it works with Variables, Events, Tags and Layers!)

Regards,
A.
« Last Edit: February 05, 2013, 04:15:36 AM by Andrew_Raphael_Lukasik »

escpodgames

  • Hero Member
  • *****
  • Posts: 677
    • View Profile
    • Assets
Re: Safe to use large amount of globals?
« Reply #8 on: February 10, 2013, 05:31:58 PM »
Ah right. Thanks, that should help keep my global variables tidy.

I thought you meant it would do it in the globals window :P .. which is why it wasen't working :)