Jump to content

  • Log In with Google      Sign In   
  • Create Account


- - - - -

Inconsistent behavior with dictionary and enums

  • You cannot reply to this topic
2 replies to this topic

#1 iraxef   Members   -  Reputation: 338

Like
0Likes
Like

Posted 25 July 2014 - 01:15 PM

enum foo { a, b, c };

void main()
{
    print("b: " + b);   // "b: 1"

    {
        dictionary d = { {'enumVal', 1} };
        int val = int(d['enumVal']);
        print("val: " + val);   // "val: 1"
    }

    {
        dictionary d = { {'enumVal', b} };
        int val = int(d['enumVal']);
        print("val: " + val);   // "val: -1076139224"
    }

    {
        dictionary d = { {'enumVal', b} };
        foo val = foo(d['enumVal']);
        print("val: " + val);   // "val: 1"
    }


    MyAppDefinedEnum mode = MyAppDefinedEnum(10);

    print("mode: " + mode); // "mode: 10"

    {
        dictionary d = { {'mode', mode} };
        MyAppDefinedEnum m = MyAppDefinedEnum(d['mode']);
        print("m: " + m);   // "m: 10"

        one(d); // "m: 211380360"
        two(d); // "m: 10"
    }

    {
        dictionary d;
        d['mode'] = mode;
        MyAppDefinedEnum m = MyAppDefinedEnum(d['mode']);
        print("m: " + m);   // "m: 10"

        one(d); // "m: 3"
        two(d); // "m: 10"
    }
}

void one(dictionary@ d)
{
    MyAppDefinedEnum m = MyAppDefinedEnum(d['mode']);
    print("m: " + m);
}

void two(dictionary@ d)
{
    int m = int(d['mode']);
    print("m: " + m);
}

When you're storing a script-defined enum in a dictionary, it doesn't implicitly 'cast' to an int.. retrieving it as an int (which, logically, is what it is) returns a bogus value.

 

When you're storing an application-defined enum in a dictionary and passing the dictionary by handle to a function, you cannot retrieve values as the application-defined enum, you have to do it as an int (in order to get the correct value).

 

32-bit linux, revision 1985 (Version 2.29.2 WIP - 2014/07/2014).

 

Thank you!



Sponsor:

#2 Andreas Jonsson   Moderators   -  Reputation: 3309

Like
0Likes
Like

Posted 25 July 2014 - 03:59 PM

Looks like a bug in the dictionary add-on.

 

I'll look into it.


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

#3 Andreas Jonsson   Moderators   -  Reputation: 3309

Like
0Likes
Like

Posted 17 August 2014 - 12:57 PM

Fixed in revision 1990.

 

Regards,

Andreas


AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game





PARTNERS