playMaker

Author Topic: Sending information between Playmaker and my own C# scripts  (Read 30154 times)

LiveWire

  • Playmaker Newbie
  • *
  • Posts: 7
Hi there, I'm new to both programming and Playmaker so hopefully this is a simple question to answer.

I'm trying to get Playmaker to talk to C# scripts that I've written. I know playmaker has the Invoke Method and Send Message Actions that allow me to run a custom script outside of Playmaker, but I can't figure out how to send information back the other way.

e.g.1: Use Invoke Method action to run a C# script and have it return a value to Playmaker.
e.g.2: Send an event to a Playmaker script from a C# script

Any help would be much appreciated. I've found Playmaker to be immensely useful but there are times where I've found a simple C# script would be simpler solution to a particular problem or I'm trying to hook playmaker up with an existing script.

Thanks!

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Sending information between Playmaker and my own C# scripts
« Reply #1 on: June 03, 2013, 07:46:40 PM »
Try Get Property and Set Property.

There is a video tutorial on it. That's what I use to pull variables out of scripts.
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

LiveWire

  • Playmaker Newbie
  • *
  • Posts: 7
Re: Sending information between Playmaker and my own C# scripts
« Reply #2 on: June 04, 2013, 07:45:44 PM »
Thanks for mentioning the video tutorial Lane, I had looked quickly at Get Property and Set Property before but I couldn't figure out how to make the object variable work in order to use them. The video tutorial explained it, so thanks for that!

I'm still unable to find a way to send an Event to a FSM on an object from an outside script though. Surly there must be some way to call an FSM from withing a script and tell it to run?

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Sending information between Playmaker and my own C# scripts
« Reply #3 on: June 04, 2013, 08:07:47 PM »
Ah, i seem to have misunderstood.

I don't know the answer, haven't done that before. Found this thread though - maybe it can help? There are a few others, but mostly about sharing variables, which is easier.

http://hutonggames.com/playmakerforum/index.php?topic=3898.msg18151#msg18151


Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

LiveWire

  • Playmaker Newbie
  • *
  • Posts: 7
Re: Sending information between Playmaker and my own C# scripts
« Reply #4 on: June 05, 2013, 07:41:18 PM »
I came across this video last night (in fact it's the last one in a series that I've been working though over the past few days) and it answers my question:


very straight forward! :)

SirGatlin

  • Playmaker Newbie
  • *
  • Posts: 17
Re: Sending information between Playmaker and my own C# scripts
« Reply #5 on: June 07, 2013, 09:35:53 PM »
Hey, I am trying to accomplish the same thing and have noticed that the Video shows how to send and Event from JavaScripting where as I would like to do it with c#. Is the code the same for c# and if not how may I go about doing this with c#?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sending information between Playmaker and my own C# scripts
« Reply #6 on: June 10, 2013, 02:01:15 AM »
Hi,

 the code is the same, the different between javascript and c# is mostly in the way you declare variables.

http://wiki.unity3d.com/index.php/Csharp_Differences_from_JS

bye,

 Jean

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: Sending information between Playmaker and my own C# scripts
« Reply #7 on: June 10, 2013, 01:39:23 PM »
Hey,

I'm having the same issue of pulling variables out of scripts, do you know where the tutorial for that is?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sending information between Playmaker and my own C# scripts
« Reply #8 on: June 11, 2013, 01:14:26 AM »
Hi,

 you mean, you want to send a variable from a script to PlayMaker or send a variable from PlayMaker to a script?

bye,

 Jean

Lane

  • Administrator
  • Hero Member
  • *****
  • Posts: 2511
  • Mender of the past
    • Cleverous
Re: Sending information between Playmaker and my own C# scripts
« Reply #9 on: June 11, 2013, 07:22:26 AM »
Hey,

I'm having the same issue of pulling variables out of scripts, do you know where the tutorial for that is?

Simple version:

You attach a script to an object in the hierarchy then drag that script from the inspector into your FSM. You may need to press the lock button on the playmaker editor window so it doesn't change the FSM shown.

More detailed video using other actions:
Products by Cleverous
|| Vault Core : Database
|| Vault Inventory : Multiplayer Inventory
|| Vault Attributes : Character Stats
|| That Hurt! : Dmg Floaties
|| Quinn : 3D

ryf9059

  • Full Member
  • ***
  • Posts: 100
Re: Sending information between Playmaker and my own C# scripts
« Reply #10 on: June 11, 2013, 12:05:46 PM »
you mean, you want to send a variable from a script to PlayMaker or send a variable from PlayMaker to a script?

I want to send a variable from script, or return a value from a function inside a script.

You attach a script to an object in the hierarchy then drag that script from the inspector into your FSM. You may need to press the lock button on the playmaker editor window so it doesn't change the FSM shown.

I watched the video and tried myself but feel a bit confused, what are those properties of that script? Are those variables inside the script? The thing is I do not recognize any of those property in my script:



This is the property displayed for Player script, but I don't have any of those variables, I only have a skeleton variables which is not shown.

Here is the script, I didn't include other functions that's not in update.

using UnityEngine;
using System.Collections;

public class Player : MonoBehaviour {
   private tk2dSpineSkeleton skeleton;   
   void Start () {
      skeleton = GetComponent<tk2dSpineSkeleton>();
   }   
   void Update () {
   }
}

Could you explain?

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Sending information between Playmaker and my own C# scripts
« Reply #11 on: June 11, 2013, 02:58:49 PM »
Get and Set Property will find *public* fields and properties.

They also show all the properties inherited from MonoBehaviour.

Sobek

  • Playmaker Newbie
  • *
  • Posts: 10
Re: Sending information between Playmaker and my own C# scripts
« Reply #12 on: July 22, 2013, 08:24:33 AM »
Hi

I am also trying to access a playmaker FSM from a .cs script. In this tread Jean mentioned that the code in the tutorial is the same for c# as well, but i cant run my code sense i added the variabel and the line of code that will fire of the playmaker event. 

this is the variabel:

Code: [Select]
var sendFSM : PlayMakerFSM;
sendFSM = GameObject.Find("EndOfLevelObject").GetComponent.<PlayMakerFSM>();

And this is the script i wrote that will fire of an FSM event once the level is completed:

Code: [Select]
private bool IsLevelClear ()
{
for (int y = 0; y < rows; y++) {
for (int x = 0; x < columns; x++) {
if ((gridDescriptor [x, y] != (int)TileType.NoTile) &&
                    (gridDescriptor [x, y] != (int)TileType.Done)) {
return false;
}
}
}
Debug.Log("Level is Completed);
sendFSM.Fsm.Event("LevelCompleted");
return true;

i get these  following error messages:
Assets/Scripts/Board.cs(551,21): error CS1519: Unexpected symbol `:' in class, struct, or interface member declaration

Assets/Scripts/Board.cs(551,35): error CS1519: Unexpected symbol `;' in class, struct, or interface member declaration

Assets/Scripts/Board.cs(553,17): error CS1519: Unexpected symbol `=' in class, struct, or interface member declaration

Assets/Scripts/Board.cs(553,34): error CS1519: Unexpected symbol `(' in class, struct, or interface member declaration

Assets/Scripts/Board.cs(553,68): error CS1519: Unexpected symbol `<' in class, struct, or interface member declaration

Assets/Scripts/Board.cs(553,81): error CS1519: Unexpected symbol `>' in class, struct, or interface member declaration

 :(

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sending information between Playmaker and my own C# scripts
« Reply #13 on: July 28, 2013, 04:41:07 PM »
Hi,

 Can you pm me with the full script, I need to see exactly what line it is and try to pint point the problem.

bye,

 Jean

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Sending information between Playmaker and my own C# scripts
« Reply #14 on: July 28, 2013, 07:07:50 PM »
Quote
i get these  following error messages:
Assets/Scripts/Board.cs(551,21): error CS1519: Unexpected symbol `:' in class, struct, or interface member declaration

You're using the Javasscript convention for defining the variable type.

Instead of:

var sendFSM : PlayMakerFSM;

it should be

PlayMakerFSM sendFSM;

There may be other problems in the script, but that error could also lead to the others...