playMaker

Author Topic: Simulating method calls with return value in playmaker?  (Read 1604 times)

ramones

  • Playmaker Newbie
  • *
  • Posts: 42
    • View Profile
Simulating method calls with return value in playmaker?
« on: September 28, 2015, 04:29:39 AM »
Hi,

Is there any way to simulate a method call (the method should be a playmaker graph or subgraph) with a return value?.

I would like to use a node for example to call another playmaker graph and get a result form it.

Cheers.

ManicMinerUK

  • Junior Playmaker
  • **
  • Posts: 51
    • View Profile
Re: Simulating method calls with return value in playmaker?
« Reply #1 on: September 28, 2015, 05:51:26 AM »
This is definitely possible, although the effort involved might be prohibitive.

You could easily use the "Set FSM <var>" actions to pass values onto another FSM, and then send that FSM an event called "DoThing"

The method FSM would do its thing with whatever variables it had when it got this event, and then set an output variable to the result and send an event to the triggering FSM (or just broadcast globally, although this is slightly slower, obv) to announce that it was finished and the return value was ready to collect.

During this process, the initial FSM could just be in an empty state that just listens for the announcement. When it gets this announcement, it uses "Get FSM <var>" to fetch the return.

As I said, it's a little convoluted, and you will need to be careful with concurrency if you are planning to call this method a lot, but it definitely works, because I've used it a few times myself.

ramones

  • Playmaker Newbie
  • *
  • Posts: 42
    • View Profile
Re: Simulating method calls with return value in playmaker?
« Reply #2 on: September 28, 2015, 06:20:04 AM »
Hi,

Thanks for the answer.

This is something I have been thinking about but being a programmer it felt too cumbersome and managable.

Perhaps I'm just over thinking things or trying to push playmaker to make things I did with plain c#. Is there any other way to accomplish this in a more "Playmaker way"?

Cheers.

ManicMinerUK

  • Junior Playmaker
  • **
  • Posts: 51
    • View Profile
Re: Simulating method calls with return value in playmaker?
« Reply #3 on: September 28, 2015, 09:01:38 AM »
tbh it sounds like something that would be fairly simple to write if you are already an experienced programmer - Playmaker can integrate with C# scripts fairly well (at least, based on my experience of asking proper coders to write me custom actions)

ramones

  • Playmaker Newbie
  • *
  • Posts: 42
    • View Profile
Re: Simulating method calls with return value in playmaker?
« Reply #4 on: September 28, 2015, 09:05:05 AM »
Hi,

Yes... I will do that. I was just setting up a playmaker course and wanted to show assistants its array capabilities.

By the way, I was just playing yesterday manic miner on my speccy :). You have an awesome alias ;)

Cheers.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 14400
  • Official Playmaker Support
    • View Profile
Re: Simulating method calls with return value in playmaker?
« Reply #5 on: September 29, 2015, 01:59:42 AM »
Hi,

 sub graph, are infact called "Sub fsm", and they use Fsm Templates, so it's possible indeed.

 look up this forum for "sub fsm". You also have actions like:

-  "Run Fsm" to run an fsm template within a state as a regular action
- within template you know will run as sub, use "finishFsm" action to inform the run fsm action that the template is done, and it will trigger the finish transition

Bye,

 Jean