playMaker

Author Topic: Sending Variables to other FSMs?  (Read 3676 times)

Red

  • Hero Member
  • *****
  • Posts: 563
Sending Variables to other FSMs?
« on: December 18, 2011, 04:20:00 PM »
I was wondering, since i'm trying to streamline what i've got on a project and i'm needing to find a way to send a variable's (in this case, a vector3) value to another object in the scene so that it can use that information in a state.

before i was using global variables but since i want to have multiplayer capabilities, having one vector3 variable that's global and accessible/used by multiple players, it would cause some issues... i have thought of a workaround of making "player 1 vector," "player 2 vector" and such but that seems a little clunky to me. i will use it but if i can find a way to pass the vector information and keep it somewhat private (as in, being able to tell a specific object the variable information as opposed to having it exposed) it would help.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sending Variables to other FSMs?
« Reply #1 on: December 19, 2011, 05:16:24 AM »
Hi,

 arrayMaker to the rescue :) Sorry I had to mention that possibility :)

 simply create a hashtable proxy and fill key/value pairs of whatever you need to store per player
so you could have a list of players ( "player 1", "player 2") and store some value for each player. AND create as many hashtable proxy as you need to store info on each player to retrive them

So you can access variable of a specific player from any other fsm by querying the hashtable for a specific player

The other ( slightly more sensible actually :) ) is to store the reference of each player together with the gameObject responsible to store info for that player ( it can be a fsm ). and retrieve that player go reference and read variable on that fsm. This is more object oriented and will scale well,

if you don't get what I mean, I can create a small example showing both variant proposed above.

 Bye,

 Jean

Red

  • Hero Member
  • *****
  • Posts: 563
Re: Sending Variables to other FSMs?
« Reply #2 on: December 19, 2011, 01:46:33 PM »
the example would probably help because the reason i went with playmaker is that i'm just not that good on programming and such that my brain was all "fwuh?"

i can see making an object that is there merely to hold and manage variables but it's the sending of those variables (or, more appropriately, the information in those variables.)

case in point... the example that i'm working on which would help is such that i'm trying to make it such that when the player is firing at something, they turn towards the object being fired at but also allow them to move... i've done this before by extracting the vector3 information from the "Get Axis Vector" action which handles the controls and through passing the vector3 as a global variable to the child which is the part of the animated mesh... and in the child's FSM i've had the "if mouse is pressed" "if mouse is not pressed" actions/states such that when pressed, point to the target as extracted with the "mouse pick" action and when not pressed, just pointing in the direction of the movement. both used "smooth look at" but with different targets to look at.

i've been trying different ways and i'm sure i'll come across one but if i could pass variable data much like calling events with the "send event" that would help streamline things because i can see how i'd need to pass that sort of information between objects... and having it such that i can send specific data to specific actions and not be exposed for "all the world to see" would help with that.

... and i fully accept that i may be overthinking things and making it more complicated than it needs to be. :P

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sending Variables to other FSMs?
« Reply #3 on: December 20, 2011, 01:02:55 AM »
Hi,

 ok, I see, ArrayMaker might be the wrong way for this then.

 Do you know you can pass a game object with an event using "Set event data" and retrieve it in the state triggered by that event using "get event info"

Imaging that this gameObject holds an fsm with variable and methods to compute and target properly.

 then, really, when you fire at something, you send an event to whatever needs to deal with the fire, that is the player and the enemy likely, and both can retrieve the gameObject and query or access variable on any fsm attached to it and act upon it doing whatever.

if you want to query for a fsm variable on a gameObject, you can simply input the fsm and variable name as string.

 So in essence, given your original query, you can also just send a value in the event.

Does that make sense.

Bye,

 Jean

Bye,

 Jean