Playmaker Forum

PlayMaker Help & Tips => PlayMaker Help => Topic started by: FrozenTarzan on September 12, 2013, 08:38:12 AM

Title: Playmaker FSM + own scripts, should they be handled via custom actions? [SOLVED]
Post by: FrozenTarzan on September 12, 2013, 08:38:12 AM
Hi Playmaker community,

Let's say I have a component for a fighting-tower with a custom AI. The tower has a mesh that can "look at" a target position and has a component that handles the internal behaviors like "seek and destroy", "offline", "follow target peacefully", "turn around as fast as possible and shoot like there is no tomorrow".

Without Playmaker I would design a FSM with code. So When the Update() of the tower is called, I would call the FSM.Update() method, which would use polymorphism to call the correct Update() method of the current state.

Now how would I use Playmaker to represent such a FSM with the visual Playmaker window?

Possibility 1: Use the internal FSM for the tower as usual and just use the events from playmaker to handle the state-changes. The communication could happen by calling a method with the "Send Message" action. But this way I still have to use my own FSM implementation.

Possibility 2: Use the FSM from Playmaker and all the events and so forth. Then in the Update() of the tower, I have a lot of if/elseif/switches that check for different parameters and adapt the behavior. Like an enum with SeekAndDestroy, Offline,... This way I can set the parameters directly via actions from Playmaker (like Set Float Value,...) but the internal design is ugly.

Possibility 3: Use custom actions for each state I can be in. So I would pass the original GameObject (the tower) to the action and this action would encapsulate the behavior? It would be like passing the tower to a generic implementation of state design pattern. In this case I would have a custom action for each state the object can be in?

Possibility 4: ...insert your best solution here! ;-)

I'll try to reformulate my problem: When I have an object that behaves differently in different states and this object has to handle code (more complex than the predefined Playmaker actions) in an Update() routine, how do I design an appropriate FSM with playmaker?
Title: Re: Playmaker FSM for custom scripts, should they be handled via custom actions?
Post by: GarthSmith on September 12, 2013, 02:00:28 PM
Hello!

I have recently dealt with similar issues with PlayMaker. My solution was pretty much your option #3.
Was that clear enough? Does anyone have any better ideas? It seems like this is how custom actions are supposed to work.

[Edit: Added the keyword "static".]
Title: Re: Playmaker FSM for custom scripts, should they be handled via custom actions?
Post by: jeanfabre on September 13, 2013, 12:04:02 AM
Hi,

 Yes this is valid. Tho I tend to use this approach when I have several actions with common features, they implement such system to prevent code redundancy.

 I tend to simply compose the class I want to work with in an action. So I simply either instanciate that class in a private variable within the action and then work with it this way, or if it's a behavior or a static class, I accomodate the referencing.

bye,

 Jean
Title: Re: Playmaker FSM for custom scripts, should they be handled via custom actions?
Post by: FrozenTarzan on September 13, 2013, 12:45:15 AM
Hi jeanfabre, hi Garth Smith,

thank you for the quick reply! I will set this to [SOLVED], even though these design questions might be interesting for a longer discussion :-)

Great community by the way!
Title: Re: Playmaker FSM + own scripts, should they be handled via custom actions? [SOLVED]
Post by: jeanfabre on September 13, 2013, 12:49:44 AM
Hi,

 Thanks :)

 Look up the wiki section and the addons specificallly, if you own few of these assets, it's really a good thing to see how playmaker bridges where designed, so tyou can get a feel of what's possible.

https://hutonggames.fogbugz.com/default.asp?W714

bye,

 Jean
Title: Re: Playmaker FSM + own scripts, should they be handled via custom actions? [SOLVED]
Post by: GarthSmith on September 13, 2013, 10:41:40 AM
Thanks jeanfabre for catching that. In my previous post...
* This base class should have a protected property with a reference to your Tower class.

Should have been:
* This base class should have a static protected property with a reference to your Tower class.

And thanks for PlayMaker. I'm finding that PlayMaker with custom actions can be very powerful and allow super quick implementation all at once.
Title: Re: Playmaker FSM + own scripts, should they be handled via custom actions? [SOLVED]
Post by: jeanfabre on September 15, 2013, 10:57:59 PM
Hi,

 Yep, PlayMaker + Custom Action is raw power and a brease!


Not sure if you are asking questions here. Do you need more input on this?

bye,

 Jean