playMaker

Author Topic: Enum Creator wizard for non coders [ECOSYSTEM] [JANUARY 2019]  (Read 8907 times)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Enum Creator wizard for non coders [ECOSYSTEM] [JANUARY 2019]
« on: January 12, 2017, 03:39:46 AM »
Hi Everyone,

 ok, new wizard for the non coders amongst us :) you will now be able to enjoy the power of Enums and FsmEnums with your own sets, without coding.

If you don't know what enums are, it's a very important part of solid and reliable coding strategy, it simply defines some hardcoded references, for example the days in a week:

Code: [Select]
enum Days { Sun, Mon, tue, Wed, thu, Fri, Sat };

and then within your code, you are safe and can't mistype or misuse week days.

PlayMaker introduced with 1.8 the ability to work with enums and create FsmVariables of type enum (FsmEnum). You can pick any available enums withint he projects, but until then if you wanted your own enum, you had to write some c# code. With this wizard you won't have to anymore.

Get the wizard on the Ecosystem



open the wizard from the PlayMaker Menu /Addons/tools/Enum Creator Wizard


and off you go,

--you can add/reorder entries, select a namespace, a name and a folder to save the enum
-- validation helps pointing out where things are not correct
-- you have a list of all your created enums at the top, you can edit them
-- full preview of the generated code



and then, you can create an FsmEnum within PlayMaker and start using it with the related actions for enum




I tried to make it as simple and obvious as possible. But of course if you have questions, don't hesitate to ask!!

Bye,

 Jean
« Last Edit: January 18, 2019, 01:33:29 AM by jeanfabre »

Fat Pug Studio

  • Beta Group
  • Hero Member
  • *
  • Posts: 1294
    • Fat Pug Studio
Re: Enum Creator wizard for non coders
« Reply #1 on: January 26, 2017, 04:01:04 PM »
Hurray!!! I was waiting for this :)
Available for Playmaker work

Thore

  • Sr. Member
  • ****
  • Posts: 480
Re: Enum Creator wizard for non coders
« Reply #2 on: September 24, 2017, 08:40:58 PM »
Wanted to add a bit of what I found out, and which might be useful to other coding newbies.

The Path
The enums, like other definitions are stored away in a specific path, which is visible when you create the enum in the FSM, and when you set the Enum Type (which is "Days" in the example above). You can sort this neatly with a namespace. This is simply a bracket around everything, like this:

Code: [Select]
namespace Gameplay.Enum {
         >enum days stuff here<
}

Gameplay.Enum and then the Enum variable is pretty much like a path like Gameplay/Enum/Days. You can call these any way you want, and create the path the way you want. This example will produce Gameplay > Enum > Days (nested twice) in Playmaker. Try this somewhere to get an idea.

It makes sense to do this, when you have several enums, and to keep a bit of order. You can also group your other scripts that way. Just put the namespace bracket around everything and it's sorted into the menu entry. However, you then also need to reference the path correctly. So when do this to your own NPCdata script, you can access it with Gameplay.NPCdata (Gameplay can be any name you want). Or Gameplay.Enum.Days etc.

You can also put it into a class. Classes have the same path structure, but don't produce a nested menu entry. Say, you have namespace Gameplay, then a class Enum, and then your stuff, you get again the menu Gameplay (as before), but this time, the specific enum looks like this "Enum+Days". So if you see strange errors, try to figure out the path, and it might fix it.

Enum in Data Script
See MdotStrange's tutorial on simple data holder or interface scripts (there are a couple of good ones).

I found it confusing first and had lots of erros when I tried to add enums to my custom data holder scripts. But it is actually simple: Once, the enum is defined, you make use of it by treating it like a custom variable type. Let's say you use the namespace snipped as I shown above (and no class) then all you need to do is place this in your variable list.

Code: [Select]
public Gameplay.Enum.Days currentDay;
I know, it looks weird for non-coders at first. But this is really the same principle as public int myNumber. IN other words, Gameplay.Enum.Days is like your own variable type, and currentDay is the variable name in the current context. Once you place this in your script, you get a drop-down list with the enums in the editor. To get or set this to the Action, you simple refer to the variable like this public FsmEnum currentDay; i.e. like all the other variables.

In other words. Somewhere (same file or another), you define the enum type(s). And once they exist in the Unity context, you can use them like your own variable types.

Changing Enums
Behind the scenes enums are integers (int), where in Jean's example Sunday is 0, Monday = 1 and so on. The names are simply counted. When you delete Wednesday (which was at the 4th position, with zero), then Thursday slips down from 4 to 3 internally and all your references are screwed up.

Code: [Select]
0 = Sunday
1 = Monday
2 = Tuesday
3 = Wednesday
4 = Thursday
5 = Friday

when deleting Wednesday, becomes...

Code: [Select]
0 = Sunday
1 = Monday
2 = Tuesday
3 = Thursday
4 = Friday

Now 3 refers to Thursday and everything that referenced Wednesday now point at Thursday, everything that pointed at Thursday now points at Friday etc.

It's thus better to not remove or add within the list (only to the end), merely replace. You can also manually assign the ints to enums, by simply writing Sunday = 0, Monday = 1, etc. When you then delete or rearrange the list, the numbers stay the same, and are not reassigned.

Enums as Flags
Last thing. Enums can also be used as flags, which allows to assign multiple categories (instead of just one drop down list), say your character has multiple attack types, not just one. The keywords to search for is bitwise and enum flags. Here's an article for this. There's are cheap assets that provide basic scripts on the Unity Store for this.

Hope this is useful for someone ;)
« Last Edit: September 25, 2017, 10:05:34 AM by Thore »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Enum Creator wizard for non coders
« Reply #3 on: September 26, 2017, 03:50:59 AM »
Hi,

 Cool write up thanks for the effort :)

 yes, The next update of the enum creatore wizard will include proper numbering to avoid the reordering issues.

 For Enum Flags. I'll be waiting for PlayMaker to support enum flags because otherwise it's pointless since you won't benefit from the flag selections because the User interface won't allow for this.

 Bye,

 Jean

Gustav

  • Junior Playmaker
  • **
  • Posts: 53
Re: Enum Creator wizard for non coders
« Reply #4 on: October 17, 2017, 11:03:17 AM »
Great, I found it! Thank you for this wizard. :)

Maybe you want to change the broken link on this page to this topic.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Enum Creator wizard for non coders
« Reply #5 on: October 18, 2017, 06:48:58 AM »
Hi,

Good point, thanks for spotting this, done :)

 Bye,

 Jean

fish

  • Beta Group
  • Playmaker Newbie
  • *
  • Posts: 18
Re: Enum Creator wizard for non coders
« Reply #6 on: December 10, 2018, 08:52:12 PM »
I posted this in the bug report but I figure it would be best to post here too.

So I am getting this error with Enum Creator every time I try to open it.

Code: [Select]
GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

NullReferenceException: Object reference not set to an instance of an object
HutongGames.Rotorz.ReorderableList.ReorderableListControl.PrepareState (Int32 controlID, IReorderableListAdaptor adaptor) (at Assets/PlayMaker Utils/External Libraries/Rotorz/Reorderable List Field/Editor/ReorderableListControl.cs:586)
HutongGames.Rotorz.ReorderableList.ReorderableListControl.Draw (Int32 controlID, IReorderableListAdaptor adaptor, HutongGames.Rotorz.ReorderableList.DrawEmpty drawEmpty) (at Assets/PlayMaker Utils/External Libraries/Rotorz/Reorderable List Field/Editor/ReorderableListControl.cs:1376)
HutongGames.Rotorz.ReorderableList.ReorderableListControl.DrawControlFromState (IReorderableListAdaptor adaptor, HutongGames.Rotorz.ReorderableList.DrawEmpty drawEmpty, ReorderableListFlags flags) (at Assets/PlayMaker Utils/External Libraries/Rotorz/Reorderable List Field/Editor/ReorderableListControl.cs:184)
HutongGames.Rotorz.ReorderableList.ReorderableListGUI.DoListField[String] (IList`1 list, HutongGames.Rotorz.ReorderableList.ItemDrawer`1 drawItem, HutongGames.Rotorz.ReorderableList.DrawEmpty drawEmpty, Single itemHeight, ReorderableListFlags flags) (at Assets/PlayMaker Utils/External Libraries/Rotorz/Reorderable List Field/Editor/ReorderableListGUI.cs:213)
HutongGames.Rotorz.ReorderableList.ReorderableListGUI.ListField[String] (IList`1 list, HutongGames.Rotorz.ReorderableList.ItemDrawer`1 drawItem, ReorderableListFlags flags) (at Assets/PlayMaker Utils/External Libraries/Rotorz/Reorderable List Field/Editor/ReorderableListGUI.cs:293)
HutongGames.PlayMakerEditor.Ecosystem.Utils.EnumCreatorWizard.OnGUI_DoEnumDefinitionForm () (at Assets/PlayMaker Utils/Wizards/EnumCreator/Editor/EnumCreatorWizard.cs:341)
HutongGames.PlayMakerEditor.Ecosystem.Utils.EnumCreatorWizard.OnGUI_HorizontalSplitView () (at Assets/PlayMaker Utils/Wizards/EnumCreator/Editor/EnumCreatorWizard.cs:133)
HutongGames.PlayMakerEditor.Ecosystem.Utils.EnumCreatorWizard.OnGUI () (at Assets/PlayMaker Utils/Wizards/EnumCreator/Editor/EnumCreatorWizard.cs:115)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:295)
UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:288)
UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:255)

I have tested this in 2018.1 (which worked) and 2018.2.18f1 (which doesn't work). Any help would be great.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7616
    • jinxtergames
Re: Enum Creator wizard for non coders
« Reply #7 on: December 11, 2018, 02:19:34 AM »
Hi.
I can confirm the issue.
I will contact jean.

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Enum Creator wizard for non coders
« Reply #8 on: December 12, 2018, 03:32:25 AM »
Hi,

 yes, I need to rework the UI, things got deprecated and the system I was using isn't working anymore.

 should be done before the end of the year.

Bye,

 Jean

craigz

  • Beta Group
  • Full Member
  • *
  • Posts: 234
    • Haven Made
Re: Enum Creator wizard for non coders
« Reply #9 on: January 17, 2019, 03:50:18 PM »
Hi again Jean,

Figured it would be easier to post on this thread since it's more of a suggestion rather than a bug :)

Is it possible to order the enum list in the creator alphabetically by the root namespace? It does tend to get a little busy/hard to sift through after a while :)

thank you for everything you do around here!

-craigz

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Enum Creator wizard for non coders
« Reply #10 on: January 18, 2019, 01:32:16 AM »
Hi,

 should be feasible indeed, I'll have a look.

 Bye,

 Jean

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Enum Creator wizard for non coders [ECOSYSTEM] [JANUARY 2019]
« Reply #11 on: January 18, 2019, 02:38:22 AM »
Hi,

 Alphabetic ordering is done as well as enum items listing when switching edits.

 please redownload from the Ecosystem.

Bye,

 Jean

craigz

  • Beta Group
  • Full Member
  • *
  • Posts: 234
    • Haven Made
Re: Enum Creator wizard for non coders [ECOSYSTEM] [JANUARY 2019]
« Reply #12 on: January 20, 2019, 06:23:17 PM »
Just downloaded!

AHH! This makes me SO happy haha :) I can't believe I never thought to ask... was struggling with this for years lol :P

Thanks again Jean!

 ;D

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Enum Creator wizard for non coders [ECOSYSTEM] [JANUARY 2019]
« Reply #13 on: January 21, 2019, 12:32:09 AM »
Hi,

 you are welcome!

Bye,

 Jean

LuminRabbit

  • Full Member
  • ***
  • Posts: 161
  • Lumin Rabbit
Re: Enum Creator wizard for non coders [ECOSYSTEM] [JANUARY 2019]
« Reply #14 on: September 26, 2020, 10:52:39 AM »
This sounds cool, not sure if I totally understand what enums are used for or can do but I’m eager to check it out for sure!
Have I said how much I love playmaker!!! This is one amazing tool