playMaker

Author Topic: I don't want to use SendMessage to access my scripts  (Read 3838 times)

AlwaysSunny88

  • Playmaker Newbie
  • *
  • Posts: 2
I don't want to use SendMessage to access my scripts
« on: September 17, 2012, 12:01:32 AM »
All the tutorials I've seen so far use SendMessage (or InvokeMethod?) internally to call methods on hand-made scripts, which is expedient but something I avoid like the plague.  Any programmers here that can tell me the best way to incorporate my own scripts into Playmaker's workflow without using Send/Broadcast Message and other known enemies of efficiency?

Also, what about calling Foo.fsm.Event("someEvent") --- is that the best way to call an event on an fsm from my code?  I can't enumerate event names somehow?  Anything that relies on using string names is something I avoid if I can help it, so this and SendMessage make me uneasy.

Edit:

I'm presently reading some documentation I previously neglected, but I'd still appreciate any additional words of wisdom regarding my reluctance to rely on string arguments.  

I'm generally feeling overwhelmed concerning when and where to rely on Playmaker versus my own code.  Any existing threads or other information along these lines may prove very helpful..!
« Last Edit: September 17, 2012, 01:20:55 AM by AlwaysSunny88 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: I don't want to use SendMessage to access my scripts
« Reply #1 on: September 17, 2012, 03:32:13 AM »
hi,

there are several solutions:

you can use singeltons for your scripts so that you can create custom playmaker actions to simply access your stuff, very much like unity api. does that make sense?

the other solution is to implemente a shake hand system for you custom actions to aquire a reference to the script, i assume you mean here components generally, so simply have a pointer within your custom action, and thenyu can obviously communicate to it best.

 another variant would be to have proxies, in the form of a component that reference both the playmaker fsm you want to communicate with and you actual script.

 don't hesitate to ask for more details, imhave several examples on the wiki, in the addons, that demonstrate al, ofnthe technics.

bye,

jean

AlwaysSunny88

  • Playmaker Newbie
  • *
  • Posts: 2
Re: I don't want to use SendMessage to access my scripts
« Reply #2 on: September 17, 2012, 02:27:13 PM »
Edit:  if TL;DR, I'm basically looking for suggestion on how to castrate PlayMaker in favor of using it solely as a way to visually plan and execute methods on my own C# scripts.  I don't want to do any computational logic with it, I just want to call global transitions from code and have PM evaluate the appropriate method(s) to call on the script that asked.  Best way to do this while limiting spaghetti and frivolous calls back and forth?


Fantastic reply, thanks so much!  A singleton pattern makes sense for several tasks, so I've been investigating the best setup with much success.  Using custom playmaker actions as go-betweens to get my scripts talking seems reasonable, though somehow I expected easier integration without using SendMessage - the ability to associate playmaker events with C# delegates, or strong enumeration of events and states to avoid needing custom actions.

Right now I'm experimenting, but having a hard time deciding where my coding stops and playmaker takes over.  I bought PlayMaker on a whim because I became frustrated with coding my custom FSM.  Now though, I wish it were simpler to use PlayMaker's visual editing to trigger method calls and coroutines on my scripts without the use of custom actions or invoke/send/broadcast message.  Not the end of the world, but quite disappointing.  Maybe I just don't know what I'm doing?

This is unfamiliar territory, so perhaps I'm not asking the right questions.  Any comments on this would be helpful.  Specifically, my current goal is creating an AI system which primarily relies on weighted steering behaviors, so an Attack Player state might represent something like AvoidObstacles + MoveTowardsTarget + Separation + Cohesion.  I already have these behaviors coded as C# scripts, and all I really need is an FSM structure to switch among tasks.  How would an experienced playmaker user approach this?

Also, are there any additional alternatives to make using playmaker more like script-to-script communicaiton?  Passing one variable at a time seems...  bad.  Maybe another layer of abstraction?  I bought playmaker to minimize the code I'd need to write for fsm management, and it already feels like I'm doing three times the work to achieve the desired results.
« Last Edit: September 18, 2012, 01:54:20 AM by AlwaysSunny88 »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: I don't want to use SendMessage to access my scripts
« Reply #3 on: September 18, 2012, 07:20:26 AM »
Hi,

 pm me, and I'll help you. It's important to see the goods to give you good advice here.

 I do work with delegates, check Input.Touches bridge or Photon bridge to see how I went for it. Basically creating bridge components, implementing the delegates that turn them into PLaymaker Events and fire them.

 bye,

 Jean