playMaker

Author Topic: enum?  (Read 8227 times)

TommyA

  • Playmaker Newbie
  • *
  • Posts: 26
enum?
« on: January 03, 2013, 06:58:05 AM »
Hi
I have a simple question.
How can I use enum variables in the Playmaker?
Could not found these kind of actions..
If there is a way, please let me know how to.
Thanks

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: enum?
« Reply #1 on: January 03, 2013, 07:10:19 AM »
Hi,

 unfortunatly not yet...

 The way I do it is to compose the enum as a string... and make a switch statement where it applies to convert back into the proper enum for setting the property back

bye,

 Jean

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: enum?
« Reply #2 on: January 03, 2013, 07:12:17 AM »
[Edit: The string idea is very nice indeed :D]
enumerates are not supported by the unity GUI. Therefore they can not be exposed, which makes them not show up in the list of object variables. For lists and hashtables you can use Jean Fabre's excellent addon "ArrayMaker" http://hutonggames.com/playmakerforum/index.php?topic=835.0 .

If you desperately need more types of enums, you can write wrappers yourself. Just create a script which contains an enum variable and then you'll be able to find the script in the object variables tab. You can then write actions which use it in the style of object(script).enum .

Did that last bit make sense ? I can elaborate if you want ;)
« Last Edit: January 03, 2013, 07:16:45 AM by kiriri »
Best,
Sven

turkeypotpie

  • Playmaker Newbie
  • *
  • Posts: 22
Re: enum?
« Reply #3 on: January 03, 2013, 08:46:32 PM »
If you're using c# to represent your enums, there are builtin methods to convert them back and forth.

To convert an enumeration value to its string representation, use the ToString method.

To convert a string to its enumeration value, use Enum.Parse:
http://msdn.microsoft.com/en-us/library/essfb559.aspx

This is probably easier than writing a bunch of switch/case statements.
« Last Edit: January 03, 2013, 08:48:40 PM by turkeypotpie »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: enum?
« Reply #4 on: January 03, 2013, 11:49:00 PM »
Hi,

 thanks for tip! I experimented with this slightly, but never found that help section somehow. Cool!

bye,

 Jean

TommyA

  • Playmaker Newbie
  • *
  • Posts: 26
Re: enum?
« Reply #5 on: January 04, 2013, 12:48:13 AM »
Thank you for great and quick answers guys!
Actually I'm not in programmer base that's why I'm using Playmaker.
It seems cool to using string and parse method.
But I have no idea about starting point to make this with Playmaker.
Could you please show me an example or more detail description?
It would be appreciated. :)

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: enum?
« Reply #6 on: January 07, 2013, 06:11:47 AM »
Hi,

ok, here we go, a simply example on how to use a FsmString to reference an enum:

Code: [Select]
using UnityEngine;
using System;

namespace HutongGames.PlayMaker.Actions
{
public class EnumAction : FsmStateAction
{

public FsmString wrapModeString;

public override void Reset()
{
wrapModeString = null;
}

public override void OnEnter()
{

if (wrapModeString.Value != "")
{

try{

WrapMode _temp = (WrapMode)Enum.Parse(typeof(WrapMode),wrapModeString.Value);
Debug.Log ("use String based WrapMode "+_temp);

}catch(Exception e)
{
string vals = String.Join(",", Enum.GetNames(typeof(WrapMode)));

Debug.LogWarning(wrapModeString.Value+" not a valid enum for WrapMode. Possible Values are: "+vals);
}




}

Finish();
}

}
}


you'll also see how I generate the full list of the enum to let the user know if the string is invalid and not representing one of the possible value of the enum.

Does that help you moving forward? let me know if you need something else,

 bye,

 Jean