Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Out of range error while importing array of enum values #53

Open
tyapichu opened this issue Dec 19, 2017 · 3 comments
Open

Out of range error while importing array of enum values #53

tyapichu opened this issue Dec 19, 2017 · 3 comments

Comments

@tyapichu
Copy link

tyapichu commented Dec 19, 2017

I'm using QuickSheet to import data from google sheets. I've tryed to import array of enum alues. QuickSheet imports data correctly (it whould be much better if you mention about flags ability of enums in documentation... i was expecting an array of enums though flags enum is more correctly). But watching on data scriptable object in Inspector leads to massive oet of range error messages spam. They appear because enumValueIndex in GUIHelper class can't handle whith multivalue enum. If enum property is multivalue the enumValueIndex returns -1 which leads to error message.

I've added some code to solve the problem my way, but i'm not experienced enouth to find professional solution of this problem.

string text = "";

if (prop.enumValueIndex >= 0)
    EditorGUILayout.PropertyField(prop); 
else
{
    EditorGUILayout.TextField(prop.name + " (int value)", prop.intValue.ToString()); 
    text = " => outofrange error";
}

    EditorGUI.indentLevel++;
    EditorGUILayout.LabelField("enumValueIndex = " + prop.enumValueIndex.ToString() + text);

Sorry if doublig...

@kimsama
Copy link
Owner

kimsama commented Dec 21, 2017

Hey, you are not the only one try to use array for `enum' type. :-)

  1. Could you tell me more details what 'flag ability of enum' you want to see in the document?

  2. I want to know why you need enum array. I wonder how and why some people try to use enum array and want to know its real user cases.

@tyapichu
Copy link
Author

tyapichu commented Dec 22, 2017

  1. I was not sure what will I get as a result of importing array of enums. To be honest I didn't know about flags attribute before I stated diging in bug. So I was expecting an array, an when I didn't saw it it debug I desided that I did something wrong it config sheet. It is probably obvious to a professional and I understand that it s right to use flags enum, but it was not obvious for me.

  2. I'm configuring list of actions i can apply to items in game inventory.

[Flags]
public enum ArticleAction
{
    NoAction = 2,
    TakeOn = 4,
    Recycle = 8,
    Open = 16,
}

So I can use Switch selection statement to choose what buttons to show and what actions to apply. For example I can Open a chest and can TakeOn or Recycle a weapon.

Several years ago I worked as game designer on project where programmers used bit flags to configure actions for items. It was easy enoth for me, so I liked this idea - one number to describe item actions. may be i could use one enum to describe differen cases like "TakeOnAndRicycle", "TakeOnAndOpen"... or I could use int field of sum of bit flags like i had to use on that project... and I would have done so if I had not dealt whith bug my way.

@kimsama
Copy link
Owner

kimsama commented Dec 25, 2017

I agree. Supporting [Flags] attribute of enum type sounds great.

I'll look it later.

Also I found some related pages with googling for references purpose:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants