Playmaker Forum

PlayMaker News => General Discussion => Topic started by: kentcheung2000 on August 15, 2018, 02:52:48 AM

Title: How to rename global variables?
Post by: kentcheung2000 on August 15, 2018, 02:52:48 AM
Hi,

How to rename global variables?...

Thanks.

KC
Title: Re: How to rename global variables?
Post by: Fat Pug Studio on August 15, 2018, 06:38:41 AM
Unfortunately, it is not possible at this moment. So choose your names wisely.

http://hutonggames.com/playmakerforum/index.php?topic=3585.15
Title: Re: How to rename global variables?
Post by: Broken Stylus on September 21, 2018, 04:09:42 PM
BZZZZZT! WRONG QUESTION!

 ;D

One useful tip: name your local vars like "home", and the global ones like "Home". The capital letter quickly helps you differentiate the nature of the var.

I really wonder why globals cannot be renamed. There are no problems in Unity to rename about any form of prefab or any other asset.

You'll have the exact same problem with events that are global. The only way to untick the global status of an event in the Events browser is to find every single instance of it in every single FSM, make them local or delete them, and only then you'll be able to rename the global event... but it won't be used any longer.

So same deal here, be careful with the way you name your global events.
I recently decided to avoid ALL CAPS because that's stuff for the default/native events, so decided to use an underscore in front of the event's name if it's global (ex: _My Global Event).
It has the benefit of pushing the global events to the bottom of the list in the Events browser window.
Title: Re: How to rename global variables?
Post by: Fat Pug Studio on September 21, 2018, 04:25:14 PM
Great idea, i wish i don't already have zillion variables. There are other fine ways too, you can use something like [L]LocalVariableName and [G]GlobalVariableName, though it really need an iron discipline  ;D
Title: Re: How to rename global variables?
Post by: djaydino on September 22, 2018, 06:38:53 AM
Hi.
Actually the best thing is to avoid using globals.

https://hutonggames.fogbugz.com/default.asp?W1462
Title: Re: How to rename global variables?
Post by: Broken Stylus on September 29, 2018, 10:52:28 AM
It's a pity because it's obviously quicker to be able to immediately set the result of an operation into a global var than to add a supplementary action like Set Fsm float every single time and everywhere.
Now, I already make extensive use of arrays and tables for specific elements meant to be ordered and parsed.
But by comparison, they are cumbersome to extract stuff from as it requires extra steps too in comparison to globals.
I don't know if globals were created as an after thought and if they suffer from a coder bias against that type of var management, but I find globals to be very useful if used in limited quantities.

Also, array lists and hash tables can only be set manually with only one type of var to prefill them (although different types can be added or inserter at runtime), and cannot be saved at runtime AFAIK (without using add-ons).

Some threads I found that dovetail into the issue of global vars and Jean's metadata:

http://hutonggames.com/playmakerforum/index.php?topic=15863
http://hutonggames.com/playmakerforum/index.php?topic=13603
http://hutonggames.com/playmakerforum/index.php?topic=14313.msg66420#msg66420

Typically I'd have simply made a game object with a single FSM on it to store all vars that are going to be modified by more than one FSM (if a var is modified by one FSM, keep that variable local inside this FSM).

However, reading Jean's explanation, he uses a prefab, with a FSM logically, which he'd call "metadata" or something similar.
He does not say "template" although the FSM on the prefab will serve a similar purpose, but by reading the rest of what he wrote, it sounds more like he was actually thinking about a template.
And this metadata FSM gets duplicated from the prefab on several other (important?) game objects.
Elsewhere he says he uses it only as a repository of some kind so the FSM just has a Start state with nothing inside.

I'd be tempted to have one single game object with a FSM metadata somewhere in my project but Jean found it useful to have a duplicate of the metadata prefab FSM added to different major game objects (or "organs", to reuse his metaphor).

Now, that is only my interpretation of what Meister Jean has said, better ask him directly what his sacred teachings really mean.
Title: Re: How to rename global variables?
Post by: treborjones on October 07, 2018, 05:40:02 AM
Hi folks, reading through some of this has come as a bit of a surprise to me! My projects currently make fairly heavy use of Global Variables, so.... eeeek! :-)

What's their major flaw? Anyone have any information regarding the level of impact heavy use (20-30 global variables) might have on performance? Obviously it probably depends on how they're used buy any info welcome.

Basically I'm trying to figure out if I should refactor to the metadata type setup suggested.
Title: Re: How to rename global variables?
Post by: djaydino on October 07, 2018, 08:21:19 AM
Hi.
Maybe This (https://hutonggames.fogbugz.com/default.asp?W1462) Can help :)
Title: Re: How to rename global variables?
Post by: Thore on October 08, 2018, 06:03:59 PM
Hi folks, reading through some of this has come as a bit of a surprise to me! My projects currently make fairly heavy use of Global Variables, so.... eeeek! :-)

What's their major flaw? Anyone have any information regarding the level of impact heavy use (20-30 global variables) might have on performance? Obviously it probably depends on how they're used buy any info welcome.

Basically I'm trying to figure out if I should refactor to the metadata type setup suggested.

Performance should not be the issue. The problem is that they are exposed, and by design probably updated often and from many FSMs, making them a symptom of potentially buggy design (or bug prone). If your game is simple enough, little spawning, few or no prefabs, mostly unique game objects in a fixed configuration, you should have no problem. That is, avoid them.

Quote
The use of global variables makes software harder to read and understand. Since any code anywhere in the program can change the value of the variable at any time, understanding the use of the variable may entail understanding a large portion of the program. Global variables make separating code into reusable libraries more difficult. They can lead to problems of naming because a global variable defined in one file may conflict with the same name used for a global variable in another file (thus causing linking to fail). A local variable of the same name can shield the global variable from access, again leading to harder-to-understand code. The setting of a global variable can create side effects that are hard to locate and predict. The use of global variables makes it more difficult to isolate units of code for purposes of unit testing; thus they can directly contribute to lowering the quality of the code. Source: Wikipedia  (https://en.m.wikipedia.org/wiki/Global_variable)
Title: Re: How to rename global variables?
Post by: Broken Stylus on October 10, 2018, 04:13:02 AM
Frankly, I don't get the bias against the Globals.
They are much more intuitive than the mess about metadata prefab objects this that and honestly, if I cared about coding conventions, I wouldn't be using Playmaker.

They're the best tool in Playmaker to quickly exchange AND centralize information.
So why the hatred?

I checked and there's no official drawback known for using them, in terms of performance.

Thus far, they seem to be treated like some kind of bastard child one keeps in the cave despite his huge potential.

They deserve far more love and more functions like RENAMING, showing their values in the list, ditto but through specific "stay on top" popup-floating windows which the user could also customize as to add or remove global vars for monitoring, filtering, grouping, tagging, search & replace, etc.
Title: Re: How to rename global variables?
Post by: jeanfabre on October 10, 2018, 06:48:15 AM
Hi,

well.... long post coming on that one :)


The problem is that organized structure is always paying off in the long run, it's something that experience tends to bring on the table.

It would be bad if PlayMaker encourage messy project. "Visual development" should not equate "messy project" and PlayMaker is certainly not about that. And using globals too much is considered messy for many reasons.

Of course, it's always tempting to put everything where it's faster to put... :) and yeah if you are quickly prototyping, etc etc, by all means, use globals at will.

There is no draw back in perfs, the drawback is in the long run and flexibility of your design and development. Even in pure c#, one could design only public static class with public static fields and methods and everything becomes accessible by everything else. But that's most definitly not what we are seeing as the likely way to go.

The main ( and probably only) problem with using too much globals is when a feature needs to be repeated/instanciated multiple times. If you start development and imagine that you have only one player, yeah, sure save the score in a global, save the health, and weapon choice in globals. It works, then a publisher comes and say here's $$$$!! Make it multiplayer ( local or remote), and then you are doomed... you have no way to add another player easily, because your player data is all over. your system can't grow and scale at all.

If you had gone the metadata way ( which is more tedious, yes), you would say: yes Sir, give me a week to modify the UI/UX and we are good to go, and that will impress your publisher/client: responsiveness is key for publisher/client trust. And that's the difference between making it in the game industry or not... quite simply.

Also, without going that much into extrems scenario, the simple idea of being able to reuse a feature (ie your player) , in another game is also very attractive, and that also needs proper encapsulation or data so that your player is whole and needs nothing but itself to perform.

Bye,

 Jean
Title: Re: How to rename global variables?
Post by: jeanfabre on October 10, 2018, 06:51:09 AM
Hi,

 and all that, not to try to move away from the fact that global should be renamed, I also think it's something that should be addressed, but I fear it's a difficult issue, as internaly, renaming makes it very difficult based on how PlayMaker core works. It's a pity, hopefully, one day this will become possible again ( it was possible in earlier versions of pm, but got disabled because of issues)

Bye,

 Jean
Title: Re: How to rename global variables?
Post by: Broken Stylus on October 11, 2018, 11:56:58 AM
Hi,
well.... long post coming on that one :)
The problem is that organized structure is always paying off in the long run, it's something that experience tends to bring on the table.
...

I see your point of view. I kinda figured these globals acted like public static elements anyways.
In the bigger industry (outside of small indie projects) one would logically go traditional and full code with a slightly larger team, and perhaps (at best and this is not to disparage Playmaker) allow bits of Playmaker only for the sectors of development wherein the employees would have access to a more visually intuitive approach to problem-solving and testing. Case in point, Blizzard's card game, Heartstone, for which I think Playmaker was introduced in the design process of cards, before the data would be serialized into classical data form and nothing about the Playmaker engine got put into the app.

As far as it goes for my little project, if for some reason, I had not planned a multiplayer function and would have to add one, and assuming that I would have had enough foresight as to isolate everything strictly related to my player into a "block" (game object acting as a folder) within the app's hierarchy, then copying that block would copy all the references to the same globals and I would then have to manually change them one by one, likely having to point to new globals intended for player 2.
That, for the vars that are strictly player-centric.
This is however not going to happen though and for simple projects, globals easily find their sweet spot in builds.

This problem would also be solved (I think) if one could tag (or group, a different approach) globals such as under a tag:player_1 and associate these, therefore, to some object or block about P1. Assuming a few more functions, duplicating the player block would also duplicate the globals tied to a player block, all with new names and references, and automatically tag/group them into a group dedicated to P2 (so on and so forth).

I may be wrong here but I would tend to think that near-full Playmaker projects are mostly limited to small scale products where major groups of functionalities have been planned ahead. I don't have examples in my head of large projects relying solely on Playmaker, involving teams of five or more people. But the small scale approach and a lack of sudden unfortunate surprises would tend to make globals reliable enough.

For what it's worth and to be add more grain to the mill (and yes, this thread is being so horribly hacked), I'd like to highlight what I deem useful about globals. First of all it's easy to know where they are used. Secondly, their exposure and how easy it is to access them are advantages.
The problem being that they are fixed.

So, could similar attributes be recycled to be crafted onto the usual local variables so that these local vars may be alterable in a way as to make them "enhanced local vars"?

Perhaps there should be a way to make local variables easier to access, without necessarily turning them into Playmaker Globals. Like a way to make them read and/or write ({get / set}) which would help circumventing the tedious addition of Get/Set Fsm var actions, with perhaps an option to isolate/limit them to specific game objects with modes such as "same-level-hierarchy", or "children only", plus eventually the possibility to use the / to create a group for the variable to appear in; the group could either be a name or a reference to a game object.
So when the user clicks on the variable popup menu in the action settings, there would the locals, then the vars with new abilities, and then the Globals, assuming you're trying to access the variables from a FSM that's an object that is meant to have access to the enhanced local vars.

And these vars would need to have a way to be added to groups which can be monitored in their floating windows, including what game objects and FSMs are using them.
Title: Re: How to rename global variables?
Post by: jeanfabre on October 18, 2018, 02:43:33 AM
Hi,

Interesting :)

 I have seen and worked extensively with pure c# frameworks that are far more impacting on the final game than PlayMaker, and they can lead to messy projects, doing pur c# project doesn't save you from messing it up big time... :) so the assumption that because PlayMaker is a visual development solution de facto makes it not suitable for large scale project is simply not true.

I think the adoption of PlayMaker in large project is not due to PlayMAker itself but rather due to the risk of starting with a tech that has a small developer pool. When you are dealing with a large scale project, you don't want to take risk, so going for Unity + c# only means you have more chance to replace your devs, if you start with PlayMaker... not that easy. I think this is the main issue, it's not a technical issue. Yes, some core feature are best kept in c#, but in an ideal world, games could be reach a 70/30 ratio in a favor of PlayMaker, because really, when you analyze your development, there is so much bits and bobs for secondary animation, little things, menus, etc etc, that simply are faster to develop with playmaker... period.

When I was at Unite last year, many sceptical c# dev came to me and ask: Show me that you can do 'this' and 'that' and how fast you can do it. The result was always overwhelmingly in favor of PlayMaker. First because you don't recompile Unity... huge factor, then because debugging is a lot more direct because you visually sees everything defacto ( we can improve here, but you get it, that with c# you have to start a debug session, etc etc), third because actions are hiding away all the little hacks and tricks you always need, and once an action is written, you benefit from the development of it. Honestly, when I write a c# monobehavior, it feels sometimes as if I'd have to use the terminal to navigate to my files on my computer... it's that bad :)


PlayMaker core dll is really a few classes reading out the state graph and calling actions, we are talking about only a few levels of indirections. Most OOP, MVC or more complex variants dedicated to Unity will have a lot more level of indirections indeed.

How much development in your Unity project is visual to begin with, imagine starting with just visual studio... no interface to view your scene, no drag and drop, no previews, no inspector none of that... so we have to understand that visual doesn't equate lack of performance or lack of scalability. It is a different way to work and as such requires a different approach to development.

So in that way I understand why you are relying on global variables heavily. The suggestion you made have been suggested before ( by me and others), but I think it was not implemented for several reasons, mainly to avoid complex setup that would confused beginner. Now that PlayMaker is mature and used but seniors, it starts to make sense, and brainstorming new ways to organize data make sense. This is hopefully what PlayMaker 2.0 will be about.

Also, there is nothing wrong with using SetFsmXXX and GetFsmXXX, they have no perf impact or anything. it's just one way to access data on other fsm.


Bye,

 Jean

Title: Re: How to rename global variables?
Post by: edufurla on October 18, 2018, 08:27:14 AM
Would be good have a way to change global variables because at the beginning of the projects we, unfortunately, choose lazy or bad names, but I have to agree with the senior users. In my first projects I used tens of global variables and in the end, worked, but it was a mess and almost impossible to make changes. Now I try to keep them as a minimum, (more to carry information between scenes or address important prefabs) and use a lot of GetFSMs. It is just one step more than use Globals, besides being cleaner and it is more easy to track how the data circulates during the game.
Title: Re: How to rename global variables?
Post by: jeanfabre on October 19, 2018, 04:56:45 AM
Hi,

 well, it's a shame we can't rename globals to begin with no matter what, there is no excuse for this, it's just wasn't developed the right way for and it had to be disable to avoid breaking projects.
 
Bye,

 Jean
Title: Re: How to rename global variables?
Post by: Broken Stylus on October 25, 2018, 10:32:27 AM
Also, there is nothing wrong with using SetFsmXXX and GetFsmXXX, they have no perf impact or anything. it's just one way to access data on other fsm.

These are fine actions, true.
But I'm a lazy bum (;D) and having access to vars in the action's var list is soooooo much faster and practical.
Imagine that for all your global events, you'd have to go fetch them from another FSM before even being able to use them in your current FSM.  :o :o
Etc.
Title: Re: How to rename global variables?
Post by: jrDev on May 26, 2019, 11:28:31 PM
Hello,

I know this topic is old but I just noticed this thread when searching for global usage and realized that no one has given the workaround for renaming. I recently had this issue with renaming globals and figured out that you can go in the debugging of the inspector window after selecting the playmaker global scriptable object and just rename it from there.

Hope this helps anyone else in future until Playmaker adds this feature.

Thanks,
jrDev
Title: Re: How to rename global variables?
Post by: Fat Pug Studio on May 27, 2019, 02:55:33 AM
Are you sure it works without any fuckups? Can Jean and Alex confirm this is a valid way to change globals and not break references?
Title: Re: How to rename global variables?
Post by: jeanfabre on June 04, 2019, 04:09:39 AM
Hi,

 ooh oh :) yeah, make sure you totally backup your project before doing so, but yes, global renaming was disabled in the interface because there are corner cases which creates problem, but for straight cases, renaming would still work, so there is a good chance that renaming global var would work in 90% of the cases, but we can't enable a feature that fails 10% of the time...

PlayMaker 2.0 will definitly address this kind of issues.

Bye,

 Jean
Title: Re: How to rename global variables?
Post by: antus on March 29, 2022, 07:41:21 AM
Hi,

 ooh oh :) yeah, make sure you totally backup your project before doing so, but yes, global renaming was disabled in the interface because there are corner cases which creates problem, but for straight cases, renaming would still work, so there is a good chance that renaming global var would work in 90% of the cases, but we can't enable a feature that fails 10% of the time...

PlayMaker 2.0 will definitly address this kind of issues.

Bye,

 Jean

The user creates a global variable A and then a global variable B. Is it possible to implement a button that changes all references to global variable A to global variable B?then manually delete global variable A?
Title: Re: How to rename global variables?
Post by: djaydino on March 29, 2022, 03:22:22 PM
Hi.
No, you will need to manually replace them.
by rightclicking on the global variable, you can find where they are used