playMaker

Author Topic: stat  (Read 5026 times)

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • Permaximum Betty
stat
« on: August 11, 2011, 09:10:50 PM »
Well im start writing a new game.
This game will use Playmaker alot .-)

First thing I will do is the AI.
But i did just think about one thing.


Every object in the game shall have some stat.
Those stat will later be looked at with the AI.
The AI will do different stuff depending on what stat the object has.

So how do setup the stat the best way with Playmaker?


Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: stat
« Reply #1 on: August 12, 2011, 01:01:10 AM »
Does the stat need to be saved across sessions?

If not, you could just use an Fsm Variable for each stat and use actions to check their values to make decisions. You can expose the variables in the Inspector panel to make them easier to tweak.

If you need to save the stats look into the PlayerPrefs actions. However, that seems best for saving the stats of objects that are known about at edit time (e.g., the player), rather than objects spawned at runtime (e.g. a crowd of enemies each with their own stats). But others may have better suggestions, or custom actions for this...

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: stat
« Reply #2 on: August 12, 2011, 01:49:42 AM »
Hi,

 I have something similar going on. So far I use the following technic and it works fine:

 For each of your "object" that needs maintaining stats or "status" I create a special "meta data fsm" attach to the "object" that simply holds them variables, this is like my interface to this object. If that "object" has children, they also read and write to this meta data fsm.

 So when your AI needs info on an object, it knows it can find a "meta data fsm" and query for known variables. If you are consistent, you can do powerful things and don't need to hard code AI for each different object if they comply to a certain set of variables.

The problem comes when you need to register to a variable change ( your AI wants to react to a variable change, and you don't want to wire the ai within your object for encapsulation reasons). For this, my meta data fsm is actually attached to a "meta data gamObject" whose sole purpose is to maintain all these sensitive data, and I have a fsm per variable, featuring and event used to set the data, I do not directly set the variable: like so I can alert the outside world when it changes. I use events to set this type of variable and therefore I can not only set the variable in the meta data fsm but also can throw events or even broadcast changes and even fill the event data with the new value.

When the current set of variable is not flexible enough ( when you need enumeration and stuff like that), I use a fsm states as my "variable". that is I have a fsm that features a series of state representing an enumeration. And I simply query this fsm and ask for the current state. This is in practice very useful indeed. I control this fsm from another fsm ( so that it only contains the required states for the enumeration).

All in all, the biggest problem you can face with this is loosing track of who is responsible for what, so be sure to maintain documentation of some sort so that in few month time you don't waiste your day tracking who is setting this bloody variable when it should not. Respect encapsulation as much as possible ( as if all your variable within a specific context where private), else this becomes a nightmare.

Hope that helps,

 Jean

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • Permaximum Betty
Re: stat
« Reply #3 on: August 12, 2011, 04:31:09 AM »
Wow Jean.

I guess you did write exactly what I was thinking about how it would be done.
And combine this whith playerpref to have a save function should work perfect.

But im still learning Playmaker as you know and if you can make a little demo with this would be awesome.
That demo could also be in the lab in playmaker.
For I know this must be something all sooner or later face when doing games.
Like I did say I want to do as much I can in playmaker.


Hmm is there any "empty" action that has only a comments you can write?
That would be awesome to add in any FSM so you can comment in the FSM.
I know you can do it in the header, but it would be nice if you could do it later.
Or even put a comment field on every action :-)


jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: stat
« Reply #4 on: August 12, 2011, 01:46:58 PM »
Hi Damian,

 I am completely overloaded ( drowning is the word...) with work currently, don't even have the time to help Alex testing the beta...  ( on top of that, we are expecting our second child  end of august... really cool!, but doesn't really help with time management :) )

If you think that it's useful,  I can put together a working project showing how I handle this kind of stuff. that would indeed a good way to share opinion and evolve, improve and  find new, more efficient ways to work with playmaker. But it will be in few weeks, not right now I am afraid. I am also waiting for 1.2 to become live and release a series of custom actions, that will need to be done before, I want to link each actions to a help section in the wiki, that will require some work to build all this help.

If you have specific question meanwhile, I will be more than happy to help tho.

 Bye,

 Jean

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • Permaximum Betty
Re: stat
« Reply #5 on: August 12, 2011, 02:00:28 PM »
Well I kind of need it fast.. lol.
i do try out new beta and report if I see strange things.
I shall try to build something and hope it will work.
I was just what you did wrote was exacly what it did think of, but dont know how to do it.
But if you dont have time I understand :-)
I will try to write the AI first and do little about the game world.
So this system can be a little later in the project.
Need to figure out some other things to.

Hope Alex find all stuff he need to make 1.2 ready for release. :-)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: stat
« Reply #6 on: August 12, 2011, 04:13:10 PM »
Hi,

What concept you actually don't understand? let me clarify the steps:

 Say you have a robot. It has a root game object. Attach to this gameObject a fsm called "META DATA" or something.

 Now every variable or property that define the robot should go there. Typical example: the robot is holding an object. You need a boolean flag to know if the robot is holding something: define this fsm bool var in "META DATA" like "is grabbing".

 Now the claw that will detect and grab an object is a game object within the hierarchy of this robot. The fsm responsible for detecting and managing the claw will set directly the "is grabbing" bool at "META DATA". It will not host a duplicate of this property. You have only one variable responsible for this property. This is the key to remain sain over time as the project will grow. If several fsm keep their own reference to something identical, you will for sure run into variable sync problems as the spec changes or when it gets more complex.
Note that any gameObject can access that "META DATA", say your robot has a floating head not necessarily attached within the hierarchy of the robot itself, no problem since you can reference any fsm. My point being: it's really up to you during developing to enforce the right strategy and the right encapsulation of data.

 Now, your AI wants to know at some point if the robot is holding something: all the AI needs to query is the meta data fsm attached the the robot root game object. Everything within "META DATA" can be read from external systems ( read: anything that is not the robot but needs to get properties from the robot).

new case:

 Now if you want to communicate with the robot and tell him about the speed he should move at. You have two options, the easiest is to set the speed variable hosted in "META DATA" but that dangerous and not very efficient. it's dangerous because as your project will get more and more complicated, you will certainly loose track of who set this speed variable when it actually should not... not a pretty sight to debug, when you have 70+fsm... Instead you can create an event "SetRobotSpeed" and fill the float variable of the event data to the speed it should reach. Now you dont necessarly need to host this event in "meta data", you can create a new fsm for it, host this event, extract the speed value from the event data, and then take all the appropriate state to inform the robot and the various parts that need to know about a speed change. This is much better than polling constantly for the speed ( yet, sometimes it's simpler and easier, which is ok if it's something occurring almost constantly during your game loop).

 The same is true if you want your robot to send event to the outside world. Say: the robot itself decided to adjust the speed: If you only set the variable, other elements of your world will not be aware of this change ( and will have to poll for it, not very nice in a game loop...).
 If you instead use an event to set the robot speed internally, your fsm responsible for the speed variable received your internal event like "SetRobotSpeed" ( you can reuse the same event, tho be careful of infinite loop, use a different event or check for the sender so that it doesn't get back a speed change... since he's the one who initiated the change, that will not be good... ). Like so, you can in turn alert the outside world about a speed change like "RobotDidChangeSpeed" and conveniently set the event data float to the new speed value.

think of this like an interface layer hosting variable and catching events coming from the outside world as well as from internal parts. This is a sain approach, maybe not the fastest to implement, but a safer one. Playmaker give us total freedom, this is real cool but can be a very bad thing if not carefully constraint into something rational and logical.

 Hope this is clear.

 Bye,

 Jean

Damian

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 188
    • Permaximum Betty
Re: stat
« Reply #7 on: August 12, 2011, 04:50:34 PM »
I think I understand. I do like example more.lol.
Its that im a coder so it will take some time for me to think in the "playmaker way".
But im learning a lot. :-)
Also if I do stuff the right way I dont need to rewrite everything after some time.

Thanks for helping out :-)

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: stat
« Reply #8 on: August 13, 2011, 12:50:04 PM »
Hey Congrats Jean!!!!!!!

Our new little bundle is 4.5 months now.. where did it go.

Q

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: stat
« Reply #9 on: August 13, 2011, 01:01:46 PM »
Just read Jeans example post.. good stuff.. And it takes time to write these example posts so if Jean does not have time to make examples then lets be very happy for written ones..

And you said that you are a coder which i am not but i have taken coding courses in the past..

I remember that when you have a function that has variables you dont let external processes write directly to those variables you write functions to set and get them... I think this is a similar concept to what Jean is saying..

You could even have a global event that gets triggered for any update on your ROBOT.. so that the AI and other processes dont have to check for changes.. Unless they have to for constant changing data.. I guess that is basically what she said about the RobotDidChangeSpeed event..

Anyway.. I think your best bet is to start writing your own example based on what she wrote and then if you get stuck post questions..

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: stat
« Reply #10 on: August 13, 2011, 01:44:24 PM »
Hi qholmes,

Quote
Anyway.. I think your best bet is to start writing your own example based on what she wrote

 I am actual a male :) Jean is a male name in france..  ;) but yes, time files with babies anyway :)

 Bye,

 Jean

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: stat
« Reply #11 on: August 13, 2011, 02:00:23 PM »
You know i deleted that and then put it back in....  ;D

Sorry i know it can be either male or female so i made a guess and went with it and figured i would be corrected either way....

Congrats!!! to your Wife to....  ::)

Q