Enums

I have an enum, how do I check the result?

I tried an if choice = left. It didn’t work.

Hm, are you doing “=” or “==” ? Something like this seems to work for me:

enum Test {
    One, 
    Two
}

// Randomly choose One or Two
let a: Test = randint(0, 1) == 1 ? Test.One : Test.Two;

if (a == Test.One) {
    game.splash("One")
} else if (a == Test.Two) {
    game.splash("Two")
}

I am doing two, let me revise my code…

image
Here it is, what am I doing wrong?

2 Likes

Two things! First, you should be checking if (direction == Test.left). Second, you’ll need to change the name of either the function or the namespace–right now, all of them are “Test” which will confuse the compiler. You could have something like “TestNamespace” and “TestFunction”, so that they are also distinct from your Test enum.

1 Like

Thanks!