playMaker

Author Topic: PlayMaker Global Variables Dumb Question  (Read 5413 times)

Fitbie

  • Playmaker Newbie
  • *
  • Posts: 31
PlayMaker Global Variables Dumb Question
« on: March 15, 2022, 05:11:00 PM »
Hi all. I recently came across a tutorial that said to use a minimum of global variables. So my question is, am I doing it right?
I have a small 2D quest with a bunch of variables (to advance the plot) and some of them are Playmaker global variables. They aren't involved in any incredibly complex logic, but they allow my game to work.
I use global variables in 2 cases:
1) To refer to the come object and not use FindGameObject. For example a player uses GetOwner and writes himself into a global variable.
2) I also use Dialogue System from PixelCrushers. The developer of Dialogue System created a very handy savesystem - it serializes all Int float bool string playmaker global variables and to save progress. I have variables for character sanity, encountered NPCs, current chapter, etc.. Tell me if I am doing everything right and if there is anything critical?
 :)

ChinaUnity

  • Playmaker Newbie
  • *
  • Posts: 16
Re: PlayMaker Global Variables Dumb Question
« Reply #1 on: March 16, 2022, 02:06:30 PM »
不要使用全局变量。因为全局变量占用的消耗非常大。

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: PlayMaker Global Variables Dumb Question
« Reply #2 on: March 16, 2022, 04:05:12 PM »
Hi.
For player its good to set as global (gameObject)
this way you can reference the player as you will interact most with it.

On the player you can set a data fsm (or make a separate gameObject with a 'Data' fsm)
on the data you can set variables that you need (reference to other objects / any other variable for example health/current chanper/location etc.)

Then you can use Get/Set Fsm Actions (there are more fsm action on the Ecosystem like 'Fsm Bool Test' for example)

But if the Dialogue System from PixelCrushers does not work well with local variables maybe you should keep the variables global.
just some things to be careful with.
Don't use the same name for local and global variable.
You can not change Global variable names.

Broken Stylus

  • Beta Group
  • Hero Member
  • *
  • Posts: 825
Re: PlayMaker Global Variables Dumb Question
« Reply #3 on: March 17, 2022, 05:21:47 AM »
Global vars have advantages: they're easily seen by Prefabs and you can easily track them throughout your project and know what FSM and Game Object calls and uses them, which is simply not possible with Get/Set at all.
However, they're very static, you can't edit their name and for now it's impossible to create instances of them or groups (categories) of them, which limits them to a very centralized type of functionality (but you can always WISH for such a feature).

Fitbie

  • Playmaker Newbie
  • *
  • Posts: 31
Re: PlayMaker Global Variables Dumb Question
« Reply #4 on: March 21, 2022, 08:27:45 PM »


Then you can use Get/Set Fsm Actions (there are more fsm action on the Ecosystem like 'Fsm Bool Test' for example)


Hi! So, another question is: if my float variable is playerSpeed(it is responsible for player animations and walking speed) - which is better to use: a global variable or get fsm float every frame? Sometimes get fsm sound too hard, but I don't know how it all works on a software level. Thanks!

Fitbie

  • Playmaker Newbie
  • *
  • Posts: 31
Re: PlayMaker Global Variables Dumb Question
« Reply #5 on: March 22, 2022, 02:13:56 AM »
I'll add to my question: I did a simple mechanic today. I used Collide2dEvent, SetFloat and Wait actions. Here's the idea: when my player comes in contact with a certain collider, he sort of "moves away" from it (because it's dark and the player needs to take the candle first). That is, when a collision is detected, I just use SetFloat EveryFrame (Float is the player's speed, its global playmaker variable). And here's the question: in 9 out of 10 cases it worked. But one time, no matter how I tried, the mechanics didn't work. Only restarting the scene helped. Why is this happened? Because of Global veriable? So why it works correctrly now? Too many questions too few answers, huh

Fitbie

  • Playmaker Newbie
  • *
  • Posts: 31
Re: PlayMaker Global Variables Dumb Question
« Reply #6 on: March 28, 2022, 05:14:26 AM »
Guys... I still need help!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: PlayMaker Global Variables Dumb Question
« Reply #7 on: March 28, 2022, 08:57:00 AM »
Hi.
It's hard to say, is collision set to on enter, then you might want to try on stay.
look in the fsm's while playing to figure out what happens.

on the playmaker window on the bottom right there is a checkbox 'Debug'
you can check that so that you can see the variables inside the actions tab

Fitbie

  • Playmaker Newbie
  • *
  • Posts: 31
Re: PlayMaker Global Variables Dumb Question
« Reply #8 on: March 28, 2022, 09:48:22 AM »
Ok, what about which is better to use: Global Variable Every Frame or Get fsm float every frame? And how really critical is to use a lot of global variables (I still do not understand what their danger is)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: PlayMaker Global Variables Dumb Question
« Reply #9 on: March 28, 2022, 10:41:31 PM »
Hi.
you can have a look to this wiki :
https://hutonggames.fogbugz.com/default.asp?W1462

if you are letting the collider object set the speed on the player, then i don't think that is a good way to do this.

i would rather (for example) send an event to the player control fsm to stop the controls and do a force impulse pushing away from the collider it hit.
then have a small delay (wait) and enable player control back

Fitbie

  • Playmaker Newbie
  • *
  • Posts: 31
Re: PlayMaker Global Variables Dumb Question
« Reply #10 on: March 29, 2022, 03:14:47 AM »
It says 'This is bad design practice, look up 'Metadata' on the forum.' - What is this? Where can I see it?

Fitbie

  • Playmaker Newbie
  • *
  • Posts: 31
Re: PlayMaker Global Variables Dumb Question
« Reply #11 on: March 29, 2022, 09:04:44 AM »
And one more thing: does this apply to Global Events? Or can there be an unlimited number of them? Thanks!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: PlayMaker Global Variables Dumb Question
« Reply #12 on: March 29, 2022, 03:20:40 PM »
Hi.
On the top right on the forum pages you will see a search bar, there you can search for "Meta Data" and find several posts.

Global events are different.

But for example if you use Send Event and use Broadcast.
Unless you need tons of other fsms to receive this event, this is bad design and also might decrease performance.

Fitbie

  • Playmaker Newbie
  • *
  • Posts: 31
Re: PlayMaker Global Variables Dumb Question
« Reply #13 on: March 30, 2022, 03:43:43 AM »
No, I wanted to know about the fact of using Global Events. Doesn't it harm how using Global Variables, if I have 30 of them for examp)

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: PlayMaker Global Variables Dumb Question
« Reply #14 on: March 30, 2022, 09:33:58 AM »
Hi.
There should be no problem using multiple global events.

a good tip : if you make events you can do this : 
Player/Jump
Player/Walk
Player/Run

This way when you need to select from the list they will be grouped