playMaker

Author Topic: Use local variable to set global?[SOLVED]  (Read 2629 times)

krane

  • Junior Playmaker
  • **
  • Posts: 63
Use local variable to set global?[SOLVED]
« on: February 08, 2017, 12:53:15 PM »
I would like to update a global variable with a local on scene change.

I have defined global string var as GlobalString. local let's call it LocalString

On Start in an empty game object I have FSM with "Set String Value". I pick String Variable GlobalString and under String Value choose localString. It populates the inspector with the right value there, but if I try to use the global variable in another FSM it doesn't find the value.
« Last Edit: February 10, 2017, 02:06:57 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Use local variable to set global?
« Reply #1 on: February 08, 2017, 02:43:55 PM »
Hi,

Are you sure your action property accepts a string?

 Bye,

 Jean

krane

  • Junior Playmaker
  • **
  • Posts: 63
Re: Use local variable to set global?
« Reply #2 on: February 09, 2017, 10:06:17 AM »
Thanks. I still can't get this idea to work, although it's setting the strings OK now.
I've got 4 directional buttons that are part of a Don'tDestroy canvas (up, down, left, right). The buttons when clicked call on the global variable for Left, Right, Down, Up. On each scene, the global variables are set using a local variable which tells it which scene is next for up, down, left right.
That works.

The problem is, not all scenes have all directions, so I've set the local as "no". I then do a string compare and if the answer is "no", it should make the button inactive (I've also tried set visible).  This is not working.

On scene start, my FSM that holds the local variables makes all the buttons visible/active, then does the string compare and should set those "no" buttons as inactive. in the next scene, they should reset as active.  This is not working.

Advice greatly appreciated. Been stuck on this for days.



jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Use local variable to set global?
« Reply #3 on: February 10, 2017, 02:06:31 AM »
Hi,

Ok, two major issues in your logic:

-- you are pointing to prefabs for deactivation, that won't work, you must point to objects in your scene hierarchy,

-- you have checked "Reset on Exit", so obviously, for state "Make Invisible 2", you are deactivate and as you transit to the next state it gets reactivate... :)




Bye,

 Jean

krane

  • Junior Playmaker
  • **
  • Posts: 63
Re: Use local variable to set global?[SOLVED]
« Reply #4 on: February 10, 2017, 07:50:41 AM »
Thanks. I did try both checking and unchecking the reset on exit but I couldn't see a difference.
Without prefabs, that means I'll have to rebuild the FSM on every scene, right? Is there no other way? i.e. can GUI buttons carry over to other scenes and refer to local content?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Use local variable to set global?[SOLVED]
« Reply #5 on: February 10, 2017, 09:03:05 AM »
Hi,

 No, because it belongs to itself within the prefab instance.

Bye,

 Jean