playMaker

Author Topic: Any way to send event with object or reference to object? [SOLVED]  (Read 2121 times)

Grofit

  • Junior Playmaker
  • **
  • Posts: 73
I have a scenario where an explosion occurs and I have written a custom script which finds all entities within a radius and sends them an event telling them an explosion has occurred.

Now this bit works and is fine, however the next behaviour triggered on some of those entities is to run and take cover. This is only a quick prototype so doesnt need to be brilliant behaviour, just enough to show it working. Anyway so the entity will look fo nearby cover (check for cover objects within radius) then finds the closest and runs and hides behind it, all works well.

However the problem comes in when I want to factor in the position of the current threat (i.e explosion, person attacking etc), as if an explosion happens and it is next to a cover position, I dont want to run to that cover position even if it is closer, as there is a threat there, so this needs to be factored into the steps... however I am not sure how to do that.

So just to recap here is some quick psudo steps that occur:

ExplodingGameObject
|- Send Threat Occurred event to all entities in range

EntityWithinRange
|- Scan for closest cover
|- Move to cover

However there is no way I can think of for the ExplodingGameObject to notify the EntityWithinRange object when the event occurs that it should be listed as a threat. So then you want to run to the closest cover with the most distance from the threat, and there could be multiple threats later too.

Only thing I can think of is make the send event script register the ExplodingGameObject explicitly onto the EntityWithinRange object when it does the loop and send events. However is there some best practice way to solve this? as I dont want to use global objects as there may be 100s of entities all with different threats etc (maybe not all active in the game at once).

So any advice or help would be great.
« Last Edit: March 18, 2013, 09:17:03 PM by Alex Chouls »

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Any way to send event with object or reference to object?
« Reply #1 on: January 19, 2013, 09:12:35 AM »
Use Set Event Data and Get Event Info actions.

Grofit

  • Junior Playmaker
  • **
  • Posts: 73
Re: Any way to send event with object or reference to object?
« Reply #2 on: January 19, 2013, 09:46:43 AM »
Ah brilliant, the event sending is happening in code at the moment, is there any more "raw" api documentation for how to use SetEventData in C# (i.e. MSDN style)? or could you quickly give a quick example?

I noticed there was a SetEventData class, but couldnt find out how I should use it properly. As I already have an FsmEvent object which is fed in through the GUI action setup, and an FsmGameObject which encapsulates the object to send the event to. So currently I just use SendEvent(eventName), however it has no overloads or anything.

Sorry to keep asking so many questions, I would just rather do it the right way earlier on than dig a big hole for myself.

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Any way to send event with object or reference to object?
« Reply #3 on: March 18, 2013, 09:07:46 PM »
Sorry, just noticed that this follow up question :-[

Hopefully you figured it out, but for anyone else searching the forums for this, take a look at the source code for the SetEventData action to see how it's done.

Example:

Code: [Select]
Fsm.EventData.GameObjectData = myGameObject;
MyPlayMakerFSM.SendEvent("myEvent");