Defining enum in separate js file?

Hello!

I was able to define an enum in a separate file, and then access it on the code like this:

//Inputs.js

var Inputs = cc.Enum(
{
Up: ‘up’,
Down: ‘down’,
Left: ‘left’,
Right: ‘right’,
A: ‘a’,
B: ‘b’,
Start: ‘start’,
Select: ‘select’
});

module.exports = Inputs;

//Elsewhere

var Inputs = require(“Inputs”);

but for some reason, trying to use the enum in a property, like this:

    input : {
        default: null,
        type: Inputs
    },

gives an error on the editor: fire

Anyone know why?Am I exporting it the wrong way?

Thanks!

Hmm i found out that actually, for some reason, enums with strings wont show up in the editor – only with numbers.

So this:

var Inputs = cc.Enum(
{
Up: 0,
Down: 1,
Left: 2,
Right: 3,
A: 4,
B: 5,
Start: 6,
Select: 7
});

solves the issue

2 Likes