playMaker

Author Topic: Read/Write variable from a custom component/script via Playmaker  (Read 5720 times)

macish

  • Playmaker Newbie
  • *
  • Posts: 7
Hi

I'm a complete noob when it comes to Unity and Playmaker and i've read a couple threads about similar (or exact the same?) question.

im trying to create cardgame and created a script that contains variables to be attached as a component to the cards game objects.

i want to be able to read and write thoose 2 variables (bools)

i've read this thread http://hutonggames.com/playmakerforum/index.php?topic=1143.0

but still have some trouble to grasp the logical concept behind it.

what i have is this

Code: [Select]
using UnityEngine;
using System.Collections;
using HutongGames.PlayMaker;

public class CardAttribute : MonoBehaviour {


public bool IsInPlay;
public bool IsInHand;


void Start ()
    {
 
    }
     
void Update ()
    {
   
    }
     
}

this script is attached to my all my card gameobjects as a component




from the other thread


Hi,

 First you need to have a reference to the fsm component in your script

declare a public var:

Code: [Select]
public PlayMakerFSM theFsm;



this is the first step i don't understand (in general too much samey fsm called variables here ;) )

how does this work with 2 or more variables? it references what exactly? (sorry for silly questions hehe)


then this

Sorry, I was doing too much in one line, here how it goes:

Code: [Select]
FsmString myFsmString = theFsm.FsmVariables.GetFsmString("My string var");


myFsmString.Value = "Hello";


GetFsmBool() actually return the Fsm variable, not that value it contains, the value it contains is then accessed by .Value, that you can set or get.


so this means

playmaker needs a reference to the custom class? "theFsm"

and inside the Script you define playmaker fsm variables and give the "normal" variables values over to thoose playmaker fsm variables.

? right? wrong? (probably hehe)


then what action would be used to read/write thoose properties from several gameobjects?


any help would be appreciated

thnx in advance

cheers

mac



jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Read/Write variable from a custom component/script via Playmaker
« Reply #1 on: May 09, 2013, 01:53:45 AM »
Hi,

 any reason why you simply create fsm for your card, instead of a script? simply create a "Card" fsm attached to your card prefab, and create the "is in play" and "is in Hand" as playmaker Fsm bool variables, then accessing them is all done within playmaker.

 now, to answer your question, I think you are getting mixed up, I think what you want is being able to read the "isInPlay" from a Fsm, not the opposite. For thi, you can use the "setProperty" and "GetProperty" actions, you will find the "IsInPlay" and "IsInHand" listed when you reference your class.

 "TheFsm" is your reference for a given Fsm, it can contains any number of Fsm Variables, and you only need onr "theFsm" to access any of it's variables.

Your custom Class should infact be regular component, it will be a lot easier to work with , within Unity and within PlayMaker.

If you are beginning with Unity and PlayMaker, this is pretty advanced, and I would recommand you start with something easier, or do as I stated first, simply do everything within Playmaker.

 Bye,

 Jean

macish

  • Playmaker Newbie
  • *
  • Posts: 7
Re: Read/Write variable from a custom component/script via Playmaker
« Reply #2 on: May 09, 2013, 09:19:27 AM »
well honestly i did not even think about to use playmaker variables for the card properties.

is there a way to prefill the variables with values (except giving the cards fsm according start actions?)

since i try to make a little card game id like to use enums for suit and ranks of the cards but havent found a way to handle them.

in general i think i used the script because it was so easy to expose the data to the insepctor for easy prefill of the data

i will try and get back to you.. thanks for your swift reply :)

cheers

macish

  • Playmaker Newbie
  • *
  • Posts: 7
Re: Read/Write variable from a custom component/script via Playmaker
« Reply #3 on: May 09, 2013, 09:06:10 PM »
i switched to fsm variables and it work now but i stumbled upon a different oddity with array maker and array list shuffle, not sure if i should post in here or post a new thread for better search results (if somebody else has similar problems)