playMaker

Author Topic: How best to share variables on one object  (Read 10104 times)

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
How best to share variables on one object
« on: February 05, 2012, 02:26:25 PM »
So for my work flow i break up my FSMs into multiple FSMs on each object.. So for my mouse over Logic:

I have one FSM for getting the actual mouse over info like mouse over or button pressed or touch on and off etc.

Another FSM for modifying the look of the object like a color change or something and then adjusting it back again.

Another FSM for displaying mouse over information on the screen like a pop up box or text etc..

What is the best way to share variables between these FSMs? I am currently using Set FSM Float etc..

I wish there were Object variables like Global variables.. I dont like clogging up my Global variables with these types of things as i find it makes it overwhelming with i look at my globals list..

Q

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: How best to share variables on one object
« Reply #1 on: February 05, 2012, 07:40:02 PM »
Set Fsm Float etc. is one way.

You can also send events between FSMs and use Set Event Data and Get Event Info to share information across FSMs. This is a little more encapsulated than Set Fsm Float etc. since FSMs don't have to know about each others' internal variables.

Eventually I'd like to have a shared variable - something between a local and global variable, to make it easier to share variables across cooperating FSMs. But I have to figure out how this fits in with hierarchical FSMs which would also make it easier to share variables (sub FSMs would have access to the parent FSMs variables).

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: How best to share variables on one object
« Reply #2 on: February 05, 2012, 09:02:12 PM »
Cool... I will look at the send event data.. But this is working for now... Sub FSMs sound cool.. now in that system is only one state active still or are there more then one active at one time?

Q

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: How best to share variables on one object
« Reply #3 on: February 05, 2012, 09:54:16 PM »
One state at each level would be active. Typically you'd keep the top level very simple to keep things organized and implement specific behaviors on lower levels - if that makes sense! It's actually quite intuitive in practice, but harder to describe...

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: How best to share variables on one object
« Reply #4 on: February 05, 2012, 10:40:18 PM »
No that makes sense to me. Kind of how i organize mine now but with multiple FSMs on each object..

Sounds cool

Q

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How best to share variables on one object
« Reply #5 on: February 27, 2012, 03:35:53 PM »
Hi,

 Ideally, I'd very much enjoy a variable that can be accessed by siblings AND/OR childs. That would be a very simple and intuitive way to encapsulate variables.

Also, declaring variables as being accessible for a given fsm would be good too like a kind of "include".

Bye,

 Jean

amaranth

  • Full Member
  • ***
  • Posts: 172
Re: How best to share variables on one object
« Reply #6 on: August 15, 2012, 05:28:22 PM »
Performance-wise, would creating an FSM that only contains variables for a specific game object be a way to manage something like this? For example:

Game Object
-FSM Click button
-FSM Setup menu
-FSM Change icon
-FSM Database (contains all of the menu variables that need to be shared in FSMs above)

I'm debating on whether to implement something like this if it helps performance.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How best to share variables on one object
« Reply #7 on: August 16, 2012, 04:32:53 AM »
Hi,

 yes, that's what I am doing currently, I prefix them with "META" and I know they only host fsm variables and do not process anything. they are just repositories.

bye,

 Jean

Corny

  • Playmaker Newbie
  • *
  • Posts: 4
Re: How best to share variables on one object
« Reply #8 on: September 10, 2012, 12:09:35 PM »
What is the performance like for the SendMessage?  I heard I should avoid using that at all costs for mobile development?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: How best to share variables on one object
« Reply #9 on: September 11, 2012, 05:47:02 AM »
Hi,

 Yes, don't make too much use of sendmessage in your gameLoop, but if you use it on one stop events, you'll be fine.

sending messages is anyway only for communicating with non playmaker scripts, if that's the case, consider integrating playmaker in your script and establish more robust communication ( via custom actions, or direct access to playmaker Fsm from script etc etc)

bye,

 Jean