playMaker

Author Topic: Global Bool variable is reset when state is finished. Is this correct?[SOLVED]  (Read 336 times)

evilpikmin

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Hi all, I'm confusing myself with this issue but I'll try my best to explain it...
I am setting a global bool variable (to true) in a state, but I am confused as to why the variable is set back to False when the next state is activated. It feels like there is a simple reason I just cant see... its late... I'm going to bed... thanks for your time
zzzz
« Last Edit: July 05, 2019, 07:33:58 AM by jeanfabre »

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4436
    • View Profile
    • jinxtergames
Hi.
It can be many reasons.

Possible from another fsm that sets it to false.

Try using local instead and see what happens

btw you can use get/set fsm actions to get/set things on/from other fsms/gameobjects.

this is better than globals.

have a look at this wiki https://hutonggames.fogbugz.com/default.asp?W548
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

evilpikmin

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Thanks for the quick response! I didn't get anywhere trying to fix the global variable so now Im using 'get' and 'set'. not working for me yet :S but Im sure I can figure it out.

thanks for your help!

evilpikmin

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Hi again, so I have this working using get and set fsm variable on some test objects BUT what is the best way to do this between prefabs? A quick google tells me to use global variables but I am trying to avoid using them right?  Any help appreciated
thanks

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4436
    • View Profile
    • jinxtergames
Hi.
I Usually have a fsm that hold a whole bunch of variables (Meta Data) .
 
on that fsm @ start of the game i place references to all the gameobject that need to be referenced by other fms

For some i use find game objects, and other i might add manually in the variable.

On creating a prefab i will store it in a variable and then use set fsm gameobject to give a reference to the prefab

This way the prefab has a reference to the meta data and can get other data from the meta.

I hope you understand my explanation, if not i will try make a video about this
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

cel

  • Junior Playmaker
  • **
  • Posts: 94
    • View Profile
a video would definitely be welcome... ;)

evilpikmin

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
It feels like I am very close! I have a game object with an FSM that is assigning a random prefab to a GameObject variable. 

I want to use that GameObject variable to create an object from an FSM on another prefab.


I can see in the inspector that the random prefab is being assigned to my GameObject variable BUT...

My other FSM can not GET the gameobject variable value. In the inspector the field does not update.


Hard to explain, yes a video would be amazingly helpful, thanks for spending time on this!

evilpikmin

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Just thinking about this some more, you mentioned that you store a whole bunch of variables in an FSM. Is that FSM on a Prefab? Does it make a difference if it is a prefab or not? 

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4436
    • View Profile
    • jinxtergames
Hi,
On early stage usually its not yet made as prefab.

Later i do make a prefab of it as i usually want to load it on the start menu and then i used "Don't Destroy On Load" so it persist on al other scenes/levels.

Btw on the 'Meta' object i many times also do "Get Owner" and place it in a Global called 'Meta data'.
The advantage of using a global for the meta is that prefabs can reference to a global.
So this way you do not need to give the reference as i mentioned on my last post.

Most of my project now have only 0-2 Globals.
Before i had the bad habit to use lots of globals (Hundreds)
FOR HIRE:Playmaker/C#

Playmaker Samples <-------------> Easy Exporter <---------------------> TPA Actions

evilpikmin

  • Playmaker Newbie
  • *
  • Posts: 16
    • View Profile
Thanks for your help on this, Im still struggling with it so I must have the basic workflow wrong. But we have gone off topic from the original post about the global bools so I will start a new post with a different question :)