playMaker

Author Topic: Use playMaker global variable in script?  (Read 4949 times)

Horror

  • Junior Playmaker
  • **
  • Posts: 79
Use playMaker global variable in script?
« on: January 31, 2013, 12:37:00 AM »
Hi guys,

I'm trying to work out how I can access a global variable from playMaker in one of my scripts. I'm trying out the Geosophic leaderboards plugin but it has no playMaker support.

So basically, I have an int variable called ScoreCombineAll and I need the int score variable from my script to use that value. How would I manage this?

My expertise with this kind of scripting is... not good.

Cheers!

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

public class GeosophicPostScores : MonoBehaviour {

int score = 0;
int leaderBoardSchema = 401;

void Start ()
{
GeosophicSDK.PostScore (score, leaderBoardSchema);
}
}

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Use playMaker global variable in script?
« Reply #1 on: January 31, 2013, 12:54:17 AM »
Hi,

 Basically, you do the following:

Code: [Select]
using HutongGames;
...
...
...
int score = PlayMakerGlobals.Instance.Variables.GetFsmInt("ScoreCombineAll").Value;


 yes?

bye,

 Jean
« Last Edit: January 31, 2013, 02:32:42 AM by jeanfabre »

Horror

  • Junior Playmaker
  • **
  • Posts: 79
Re: Use playMaker global variable in script?
« Reply #2 on: January 31, 2013, 01:25:38 AM »
Hi Jean

I'm getting this error:

Assets/Scripts/GeosophicPostScores.cs(12,21): error CS0029: Cannot implicitly convert type `HutongGames.PlayMaker.FsmInt' to `int'

Also, could you get an int variable from an FSM which is sharing the same object as the script?

Thanks!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Use playMaker global variable in script?
« Reply #3 on: January 31, 2013, 02:32:23 AM »
D'oh, that's what you get with copy paste :)

add .Value to get to the int. like so:

Code: [Select]
int score = PlayMakerGlobals.Instance.Variables.GetFsmInt("ScoreCombineAll").Value;

bye,

 Jean

Horror

  • Junior Playmaker
  • **
  • Posts: 79
Re: Use playMaker global variable in script?
« Reply #4 on: January 31, 2013, 05:27:49 AM »
Thanks Jean, it looks like you may have saved my arse yet again!

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Use playMaker global variable in script?
« Reply #5 on: February 02, 2013, 03:34:02 PM »
:)