playMaker

Author Topic: "Get Owner" Command in C#?  (Read 2772 times)

jalex19

  • Playmaker Newbie
  • *
  • Posts: 27
    • View Profile
"Get Owner" Command in C#?
« on: November 09, 2012, 08:35:01 AM »
Disclaimer: This is regarding taking some functionality from Playmaker and trying to do it in code (C#)

I am trying to emulate the Get Owner command in C# - my use case is as follows : The player uses a resource node, which upon being used does a "Get Owner" and stores its gameObject as a Global PM Variable: UsedResource - it then sends a message back to the player telling it to open a menu with a progress bar. When the progress bar is finished it sends a message back to UsedResource telling it to destroy itself.

This works fine in playmaker, but for various reasons I want to figure out how to do this in code. Chiefly, I want to identify an instance of a prefab so I can specifically message it back later. Also I'd like this to eventually be multiplayer friendly - so I've heard using static variables is not a good idea?

Any help appreciated, thanks


jalex19

  • Playmaker Newbie
  • *
  • Posts: 27
    • View Profile
Re: "Get Owner" Command in C#?
« Reply #1 on: November 09, 2012, 09:35:31 AM »
I should mention that the resource node is a prefab so I can't give it a reference to the player in the inspector.

DARK_ETERNAL

  • Full Member
  • ***
  • Posts: 110
    • View Profile
Re: "Get Owner" Command in C#?
« Reply #2 on: November 09, 2012, 01:14:20 PM »
Have you opened the script?

Code: [Select]
storeGameObject.Value = Owner;
It seems that Owner is a property defined in FsmStateAction class, thus you can access it from every class that inherits from FsmStateAction.

But, you can set the FSM in the prefab itself and store the owner with no problem with Playmaker. However, if you want to identify instances of a prefab, you are to need quite a lot of different globals, if you were to instantiate many copies of your prefab.

What I'd do is something like get the gameObject property? If you have a script attached to any gameObject and you want to get THAT gameObject from it's own component...

Code: [Select]
FsmGameObject ownerGO;
ownerGO.Value = this.gameObject;

If you are accessing it from a custom action, just calling the Owner property might do. Guess FsmStateAction class manages it somehow. And, if you're attempting to send an event (perhaps via script, as well?), you should think as well on sending the event to the Fsm or PlayMakerFSM component of that gameObject.

I don't think I'm getting your problem, but I hope this helps you somehow.
Check out our new game: Nitro Chimp. Now live in App Store!

Trailer:
Download: https://itunes.apple.com/app/nitro-chimp/id557150450?l=en&mt=8

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15373
  • Official Playmaker Support
    • View Profile
Re: "Get Owner" Command in C#?
« Reply #3 on: November 12, 2012, 05:47:06 AM »
Hi,

 I am not sure what you are trying to do:

 do you plan on mixing PlayMaker with normal script or do you want to create a simple c# script not related at all with PlayMaker?

bye,

 Jean