playMaker

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

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
    • View Profile
How best to share variables on one object
« on: February 05, 2012, 12: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: 3202
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: How best to share variables on one object
« Reply #1 on: February 05, 2012, 05: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
    • View Profile
Re: How best to share variables on one object
« Reply #2 on: February 05, 2012, 07: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: 3202
  • Official Playmaker Support
    • View Profile
    • LinkedIn
Re: How best to share variables on one object
« Reply #3 on: February 05, 2012, 07: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
    • View Profile
Re: How best to share variables on one object
« Reply #4 on: February 05, 2012, 08: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: 12342
  • Official Playmaker Support
    • View Profile
Re: How best to share variables on one object
« Reply #5 on: February 27, 2012, 01: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
    • View Profile
Re: How best to share variables on one object
« Reply #6 on: August 15, 2012, 02: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: 12342
  • Official Playmaker Support
    • View Profile
Re: How best to share variables on one object
« Reply #7 on: August 16, 2012, 01: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
    • View Profile
Re: How best to share variables on one object
« Reply #8 on: September 10, 2012, 09:09:35 AM »
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: 12342
  • Official Playmaker Support
    • View Profile
Re: How best to share variables on one object
« Reply #9 on: September 11, 2012, 02: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