- Home /
how to use a value of enmu to do Mathematics operation with int type ? ( In Javascript )
help!! how to use a value of enmu to do Mathematics operation with int type ? ( In Javascript ) like:
enum aaa { ONE, TWO, Three}
var i = 5 ; var j = 6 ; var sum = i + j * aaa.TWO;
but it's wrong~
Error message is BCE0051: Operator '*' cannot be used with a left hand side of type 'int' and a right hand side of type 'aaa'.
Answer by KeithK · Apr 06, 2011 at 10:15 AM
Firstly, Enums start from 0, so calling it ONE will still yield 0 as it's value. To start your Enum incrementing from 1 you would have to define your Enum like so:
enum aaa
{
ONE = 1,
TWO,
THREE
};
As for doing maths with them, you will need to cast it to an int like this:
EDIT: Corrected cast for JavaScript.
var sum = i + j * parseInt(aaa.TWO);
This will work for how you want to use it. Though I'm curious to ask why you're doing this?
Oh damn it. $$anonymous$$y bad, thanks. I will update my post.
Answer by Eric5h5 · Apr 06, 2011 at 11:00 AM
Use parseInt() to convert an enum to its integer value.
Your answer
Follow this Question
Related Questions
Why can I not change my font style in javascript? 0 Answers
How to assign multiple EditorApplication.update delegates in JS? 2 Answers
Setting Scroll View Width GUILayout 1 Answer
Converting Array Object to int (or finding an alternative) 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers