playMaker

Author Topic: General Question: Get FSM Variable vs Global Variable  (Read 2448 times)

antibob

  • Playmaker Newbie
  • *
  • Posts: 24
    • BillsClass
General Question: Get FSM Variable vs Global Variable
« on: March 26, 2014, 04:39:48 PM »
What is the benefit of using Get/Set FSM Variable vs using a Global Variable?

I've been using Global Variables to manage player stats such as Health and Points.
Just wondering about best practice.

Thanks,
AB

haikugames

  • Playmaker Newbie
  • *
  • Posts: 25
Re: General Question: Get FSM Variable vs Global Variable
« Reply #1 on: March 26, 2014, 06:42:08 PM »
In general, I've been using Get/Set FSM Variable when a small and defined set of FSMs have to talk to each other.  They can set each other's FSM variables and no one else needs to know the information.  If I made every one of these variables global, I'd have a ton of global variables in my scene. 

I use global variables when many FSMs have to access the same information.  (For example, I might make Health global depending on your game since you might change multiple things based on whether the player was alive, dead, or nearly dead).

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: General Question: Get FSM Variable vs Global Variable
« Reply #2 on: March 26, 2014, 06:55:13 PM »
Global variables aren't meant for stuff like Health.

In the learning process or just starting out you may find this to be a good idea, but once you start scaling the game you'll start leaning toward local variables with generic fsm communications.

When multiplayer comes into the picture you have to be much more cautious about what you use for Globals.

Personally, I don't use globals, but its only because I personally understand the patterns in using the fsm communication better and feel more secure when setting up FSMs that will be used all over the place. You could use globals in singleplayer for stuff like keys, scores, equipment, really high level stuff that might be connected to the entire level or to only one object that perhaps a whole lot of other objects need to know about. For instance setting a global string to "level_typeLava" and then having one generic AI system that changes based on what level type they're instanced into by using a string compare on that global variable when they init.

I think the general advice would be don't get too low level with them, they are indeed very useful (and ideal, sometimes), but you have to be careful about using them because of their singular nature and inherit connectivity to everything. There's good cause to control the flow of information by choosing not to use global variables. Also, refactoring will take longer if you have a lot of globals.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D