Playmaker Forum

PlayMaker News => General Discussion => Topic started by: Lobohotpants on March 04, 2013, 02:02:14 PM

Title: Global variables vs Statemachine actions
Post by: Lobohotpants on March 04, 2013, 02:02:14 PM
Is it a better practice to access variables directly from FSMs by using the Statemachine actions such as Get FSM Variable/Int/Float etc... than to create global variables? 
Title: Re: Global variables vs Statemachine actions
Post by: jeanfabre on May 14, 2013, 01:59:42 PM
hi,

 It's really a question of taste and design pattern.

 I very very rarely use global variables, because it's a break to encapsulation. If global variables could be set to only be accessible within a hierarchy, that would be a different deal.

 what I tend to do, is create Meta Fsm, holding only variables, then within that hierarchy of gameObjects, each fsm that needs to look up or maintain these variables use get/set fsm var. I don't even bother checking if it is more or less efficient then using global var, it's purely because this is the way I feel confortable with it,

Enforcing encapsulation in playmaker is really something you have to decide at a design level, anything can accessed from anywhere, so you are free to do it the way you want.

 Global var are good for "global" variables...d'oh... :) I mean it actually. If your player has a property shared by several fsm dealing with that player, I tend to not use global var here, cause the day you will want two players... you are in trouble.

now, user prefs is a good place for global vars, cause they really can't be redundant.

bye,

 Jean
Title: Re: Global variables vs Statemachine actions
Post by: doppelmonster on May 19, 2013, 12:48:57 PM
Global vars are not reseted when entering a new scene or resetting a scene.
You have to do that manualy.

So i use globals only for stuff i need for all stages of the game (like the preferences) and use get/set FSM var for the communication between the FSMs.

I like the idea of Jean to create just one meta FSM with vars. I will try that on upcoming projects.