Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - HardLight680

Pages: [1]
Share New Actions / Re: Fully Nestable SubFSM Communication
« on: May 08, 2018, 12:22:29 AM »
I never really thought about doing events, but a straightforward solution might be to expose a category of string variables - such as 'Events' - and use those to specify the caller's preferred event triggers.

You would need to use some inspector magic to make sure that the exposed event controls are interpreted as FSMEvent variables instead of FSMString variables, but still get translated properly as string names. Inside the template itself, you could then use SendEventByName with the HostFSM target to send these events back up to the caller.

It looks like specifying HostFSM as the target will send the event up to the most immediate caller, so you don't need to worry about accidentally skipping levels or anything. It also bypasses the need for the events to be marked as Global, so this should work pretty well for keeping things self contained.

The only other thing that might be nice to have would be a FinishFSM variant that allows you to send an event up to the caller and end the FSM at the same time.

Most of this seems pretty straightforward, so I'll see if I can add it to this action.


I have updated the package to include the above feature. I did not add the FinishFSM variant as causing a state transition in the caller now automatically causes the sub FSM to terminate. However, since the caller is not guaranteed to respond to events sent from the sub FSM, there may still be certain edge cases where an action like this would be convenient.

So far, it seems relatively stable. There might be a minor issue with cluttering up your string variables with event holders, but it shouldn't be too bad as long as you don't go crazy.

There is also a minor issue in that adding a SendEventByName action to a sub FSM while you are in the nested FSM editor window will cause an exception in the UI. This can be avoided fairly easily if you modify the template directly by clicking on the asset as opposed to clicking on the Edit button inside the action.

Share New Actions / Fully Nestable SubFSM Communication
« on: May 07, 2018, 05:03:48 PM »
I made up a small action that allows you to run FSM templates and return data back to the caller regardless of whether the caller is a sub FSM or a host FSM. It is entirely self-contained, so there is no need to use additional actions besides the one RunFSMFunc action. There is no need for any special actions inside the sub FSM either.

The operating principles are similar to the RunFSM action. Variables with the Inspector attribute will appear as inputs, and the sub FSM may terminate using the FinishFSM action.

As a new addition, variables in the template that are inside the 'Output' category will appear as outputs which can be captured into variables for the calling FSM. Output variables are automatically copied by value up into the calling FSM's capture variables when the sub FSM ends without the need for any special actions.

Additionally, string variables in the template that are inside the 'Events' category will generate event selection fields on the action. The template FSM can use those string variables in SendFSMByName with the HostFSM target type in order to send caller specified events back to the caller.

Note that if the calling state ends while a sub FSM is still running, the sub FSM is immediately ended and its current output values are copied to the calling FSM. As a result, if a sub FSM output event causes a state transition in the caller, the sub FSM ends and its current computed values are copied out.

The package contains samples for Factorial and MergeSort FSM templates to show the basics of how it is used, and to show how this can be used for recursive FSM programming.

2018/05/08: Updated to support FSM event outputs.

* PlaymakerRunFsmFunc.unitypackage

Pages: [1]