Playmaker Forum
PlayMaker Help & Tips => PlayMaker Help => Topic started by: LiveWire on June 03, 2013, 07:40:16 PM
-
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!
-
Try Get Property and Set Property.
There is a video tutorial on it. That's what I use to pull variables out of scripts.
-
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?
-
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
-
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! :)
-
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#?
-
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
-
Hey,
I'm having the same issue of pulling variables out of scripts, do you know where the tutorial for that is?
-
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
-
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:
-
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:
(http://i.imgur.com/vKUEU9Z.png)
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?
-
Get and Set Property will find *public* fields and properties.
They also show all the properties inherited from MonoBehaviour.
-
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:
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:
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
:(
-
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
-
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...