playMaker

Author Topic: Get a variable from a none MonoBehaviour script [SOLVED]  (Read 1974 times)

Wingy7

  • Playmaker Newbie
  • *
  • Posts: 4
Get a variable from a none MonoBehaviour script [SOLVED]
« on: January 30, 2017, 06:57:14 AM »
Hello everyone,

I'm working on my android project and therefore i'm using "Play Games plugin for unity". What i want to do is get a string variable (which stores an URL of a player's avatar image) from the specific script and store it in a global FSM variable. This script cannot be attached to an object. So i can't use "Get properties" action.

I found a few solutions on this forum, but however as a complete newbie at coding, I couldn't implement the code in the script.

Here is a code of the variable i'm trying to get:
Code: [Select]
  public new string AvatarURL
        {
            get
            {
                string retval = string.Empty;
                if (authenticated)
                {
                    retval = mPlatform.GetUserImageUrl();
                    if (!base.id.Equals(retval))
                    {
                        ResetIdentity(mPlatform.GetUserDisplayName(),
                            mPlatform.GetUserId(), retval);
                    }
                }
                return retval;
            }
        }

I know that i can use this code, which gets a global FSM variable:
Code: [Select]
MyStringValue = FsmVariables.GlobalVariables.GetFsmString("MyglobalString").Value;
MyStringValue = AvatarURL;

But i couldn't implement the code in the script without errors.

Here's the full code of the script if needed:https://github.com/playgameservices/play-games-plugin-for-unity/blob/master/source/PluginDev/Assets/GooglePlayGames/ISocialPlatform/PlayGamesLocalUser.cs

Any help would be appreciated.

« Last Edit: February 02, 2017, 05:17:26 AM by Wingy7 »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Get a variable from a none MonoBehaviour script
« Reply #1 on: January 31, 2017, 01:27:12 AM »
Hi,

have you added :

Code: [Select]
using HutongGames.PlayMaker ;

Wingy7

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Get a variable from a none MonoBehaviour script
« Reply #2 on: January 31, 2017, 11:02:37 AM »
Hi,

have you added :

Code: [Select]
using HutongGames.PlayMaker ;


Yes, absolutely. The problem is that i can't put the code in a correct spot.

Wingy7

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Get a variable from a none MonoBehaviour script
« Reply #3 on: February 01, 2017, 02:02:27 PM »
Basically it's like this, i'm using this code:
Code: [Select]
using HutongGames.PlayMaker;
FsmString MyStringValue = FsmVariables.GlobalVariables.GetFsmString("gl.AvatarURL").Value;

If i put in the "Value" a random text like "Hello", i can see it in my Global Fsm Variable when i test my app.
Code: [Select]
FsmString MyStringValue = FsmVariables.GlobalVariables.GetFsmString("gl.AvatarURL").Value="Hello";
So it works just fine. But instead of setting my FSM variable with a random text, i want to set it with an URL of player's avatar which stores in "AvatarURL" variable, if i'm not mistaken.

I tried to put "AvatarURL" in the end of the main code:
Code: [Select]
FsmString MyStringValue = FsmVariables.GlobalVariables.GetFsmString("gl.AvatarURL").Value=AvatarURL;
And as you probably guessed that it didn't work quite well.  :D
So this is why i asked for some guidance on how to do this correctly,  of course If it's something simple and it won't waste your time.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Get a variable from a none MonoBehaviour script
« Reply #4 on: February 01, 2017, 02:58:19 PM »
Hi,

Maybe something like this :

Code: [Select]
var globalVariables = FsmVariables.GlobalVariables;
var myGlobalString= globalVariables.GetFsmString("myGlobalString");
myGlobalString.Value = retval;

if that does not work, try changing the last line to this :
Code: [Select]
myGlobalString.Value = retval as string;

Wingy7

  • Playmaker Newbie
  • *
  • Posts: 4
Re: Get a variable from a none MonoBehaviour script
« Reply #5 on: February 02, 2017, 05:16:22 AM »
Thank you very much for your time!

Tried to work with this code, but no success. Probably just can't put it in the right place. However found an example project where google avatar is implemented through Social Api. Gonna try to work with that.

Again, thank you very much for your assistance  :-*!