var level:Int = (Core.COUNT_QUESTIONS_IN_EPISODE:Int)
* (currentEpisode.get__index():Int)
+ (currentEpisode.get__currentQuestion():Int);
The parentheses are mandatory.
Breaking it up into different lines isn’t mandatory, but it helps. This way, when you get a “String should be Int” error message, you’ll be able to see based on the line number that the error came from get__currentQuestion(), not get__index() or COUNT_QUESTIONS_IN_EPISODE.
Are you sure currentQuestion is an Int, and not a String?
For example:
var level:Int = 30 * 1 + "8";
However, what platform are you targeting? It seems like this sort of thing would throw a compile error. Perhaps something is wrongfully typed, like __currentQuestion is meant to be an Int, but there’s a Std.parseInt missing for conversion from a JSON or other data object somewhere?
var count = Core.COUNT_QUESTIONS_IN_EPISODE;
var index = currentEpisode.get__index ();
var current = currentEpisode.get__currentQuestion ();
trace ("Is count really an Int? " + (count + 1 != count + "1"));
trace ("Is index really an Int? " + (index + 1 != index + "1"));
trace ("Is current really an Int? " + (current + 1 != current + "1"));
That means that compile-time typing is working fine. Which isn’t surprising: Haxe is pretty type-safe, while Javascript isn’t. Makes sense that the problem would happen only at runtime.
Sounds like it returns "1", not just 1. They’d show up the same if you traced them, but only the string would make it add up to 11.
And I assume _index is declared something like this:
private var _index:Int;
That’s nice and all, but when targeting Javascript, none of this guarantees that _index will be an integer. You can still assign a string to it. Or an array. Or an arbitrary object.
It isn’t random, I know that much. Javascript converts between types when it needs to, and leaves them as-is otherwise.
None of the code you’ve posted is the cause of this problem; it’s just the effect. At some earlier time in your program, you set _index to a string value. Try to figure out where.
Yes, you are right. When creating an object I sent value for variable _index received from openfl.utils.Object. And, apparently, by default these values are String. I converted it to Int and now code works fine.