playMaker

Author Topic: Command Pattern in Playmaker (i.e. queue for actions)  (Read 983 times)

neteeyore@comcast.net

  • Playmaker Newbie
  • *
  • Posts: 9
Command Pattern in Playmaker (i.e. queue for actions)
« on: March 25, 2020, 10:51:36 PM »
Was wondering if I am using the right approach (I know there are many to any problem) for creating a command pattern in PlayMaker.

In short, I ended up creating empty FSMs for the actions and creating an array to hold them.  Then I made a command processor to add/run them.  I added some logic to prevent overruns and I am using FSM for each action.  It seems to work, but was wondering if that is really my only option in playmaker.  Didn't want to miss it if there is a better/easier way.

I am building this to support the development of digital boardgames.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Command Pattern in Playmaker (i.e. queue for actions)
« Reply #1 on: March 26, 2020, 01:42:29 AM »
Hi.
I am just thinking out of my head how you could do this using lesser fsms.

I would use array maker instead of build in arrays.
As they have a reference and are more advanced than the build in array.

To store each step you could for example use 2 array lists, 1 to store the state and 1 to store the fsm.

Then you could place on each state a 'Array List Add' (2x 1 for the fsm name and 1 for the state its in)

OR

Have a 2nd fsm handle this by using 'Get Fsm State' and use a 'String Changed' and if changed, then add to array list (1 for the fsm name and 1 for the state its in)

Now to for example, revert things you could use 'Goto State By Name' (Ecosystem)

Depending on how you are adding the states you may need to set a way to prevent adding the state again.

neteeyore@comcast.net

  • Playmaker Newbie
  • *
  • Posts: 9
Re: Command Pattern in Playmaker (i.e. queue for actions)
« Reply #2 on: March 26, 2020, 01:43:30 PM »
Not sure if I am understanding this correctly.  It looks like you are talking about the ability to save game states and go back to them.  And while I am also working on that, I am after an action queue.  Something where I can send the commands to a central process to be queued and then executed,  Each action could have different parameters.  For example in my case I may have an action of deal a card.  I would have to send it a variable to know which deck to deal.  Later I will have more complex actions like initiate encounter and that could have different parameters.

What I have done is to create a controller that receives games objects.  Those objects represent the definition of an action (not the scriptable parts, just the variables)  I then have code to manage how to receive that action and add it to an array.  This helps me to control how/when actions are run and the i have a process for running the actions.  (i.e. getting the variables from the queued game object's FSM and using them to perform the action).

I have done some testing, and right now it works and seems to be pretty clean  (a bit of a headache to create objects just to run an action, but effective for moving the information to the process.

Undo is a side benefit, but this process really allows me to control the turn and when/how things happen. 

I may have mis-understood what you shared, but I think it is similar just focused on game states rather than sharing the action to the queue.

I will also have to evaluate the benefits of Array Maker vs Built in Array based on your feedback.

Thanks.  I was mostly trying to see if anyone else is facing this type of challenge and how they are solving it.