Really Major Bug in HTML5 target

Her its simple code :

var j:Int = 0;
var some:Int = 55;
test(some + j);

function test(c:Int):Void
{
trace©;
}

In flash = 55;
In HTML5 = 550;


Full code tested

var j:Int = 0;
var k:Float = 0;

	for (i in 0...15)
	{
		var symbol:SymbolGame = new SymbolGame();
		
		var d:Int = 0;
		var l:Float = i / 3;
		d = Math.floor(l);

		var comb:Array<Int> = getCombination(d);
		var position:Int = pos[d];
		var z:Int = 0;
	
		
		if (Std.int(position) + Std.int(j) > Std.int(comb.length) - 1)
		{
			z = Std.int(position) + Std.int(j) - Std.int(comb.length);
		}
		else z = Std.int(position) + Std.int(j);
		
		
		symbol.setStandardImage( comb[z] );
                   ...
	}

…public function setStandardImage(face:Int):Void
{
if (face > -1 ) this.currentFace = Std.int(face) + 1;

	this._currentPic = AssetsManager.getImage("symbol_" + this.currentFace, this._background.width, this._background.height);
	...
}

Thats works correctly on diffrent targets, but remove Std.int - in HTML5 - Int migrated to String!!!

Couldn’t replicate. What openfl/lime/haxe version are you using?


	public function new() 
	{
		super();
		var a:Int = 55;
		var b:Int = 0;
		trac(a + b);
	}	

	function trac(e:Int)
	{
		trace (e);
	}

gives out:

Main.hx:64: 55

Just for funzies, this is what the JS says:

	var a = 55;
	var b = 0;
	this.trac(a + b);
trac: function(e) {
		haxe_Log.trace(e,{ fileName : "Main.hx", lineNumber : 64, className : "Main", methodName : "trac"});
	}

Thx for u answer.
Lime/haxe/openfl - latest version

Please test my full code, not simple without Std.int
If it needed comb = [[1,2,3,4,35],[1,2,3,4,45],[1,2,3,4,55]…]]; for example
and pos[d] = 1 or 2 or 3 … and so on

When i test

if (position + j > comb.length - 1)
{
z = position + j - comb.length;
}
else z = position + j;

trace(comb);
trace(position);
trace(j);
trace(z);
trace(comb[z]);
//
[45,234,44,33,22,55,66]
1
0
2340 // wtf?
null

…and its not a final

after I set Std.int for every block

public function setStandardImage(face:Int):Void
{
if (face > -1 ) this.currentFace = face + 1;

    trace(currentFace) // some1
   // also if face = 0 for example, and current = 10 , aseets also crushes, but symbol_10 i have
this._currentPic = AssetsManager.getImage("symbol_" + this.currentFace

}

and finally after set

this.currentFace = Std.int(face) + 1;
thats works
((((

Is by any chance “this.currentFace” a string?

Try with

this.currentFace = (face + 1);

Since JavaScript has no runtime types, it won’t complain if you type something the wrong way.

Here’s an example:

var a:Int = cast "100";
var b = a + 100;
trace (b);

…on JavaScript, this will trace “100100”, and on C++, it will probably crash horribly :wink:

Haxe is strongly typed, so it guards against this, but if you ever use Dynamic an unsafe cast, you open yourself up to the risk that you may get the wrong type. Use caution

For example:

var data:Dynamic = { a: "100" };
var a:Int = data.a;
trace (a + 100);

This will produce the same problem. data is Dynamic, so the compiler assumes when you run a:Int = data.a that data.a really is an integer. This would work better if it was really a String

var data:Dynamic = { a: "100" };
var a = Std.parseInt (data.a);
trace (a + 100);

The great news is this is uncommon in Haxe development, but is much more common in plain JavaScript

miltoncandelero - no its no chance, because its class field typed Int

singmajesty - I dont understand u. What im doing wrong? I have no Dynamic , also I have no cast string to Int for example. In my code all variables has type Int or Float or Array Int - no String
but…
before i do

var cmb:Array<String> = e.data.combs.split("|");
			var fin:Array<Array<Int>> = [];
			var sml:Array<Int> = [];
		
		for (i in 0...cmb.length) 
		{
			sml = cast cmb[i].split(",");
			fin.push(sml);
		}
		
		this._model.combinations = fin;

Maybe thats broke the code later? And fin != Array Int now for JS ?
If its true - please show me the way, how cast dynamic vars to real int, on example my last code shown

Yep, that would do it. It’s the cast there :slight_smile:

cmb[i].split(","); // returns Array<String>

maybe try something like this?

var combinationData = e.data.combs.split ("|");
var combinations = [];
var split, combination;

for (data in combinationData) {
    
    split = data.split (",");
    combination = [];
    
    for (value in split) {
        
        combination.push (Std.parseInt (value));
        
    }
    
    combinations.push (combination);
    
}

_model.combinations = combinations;

Thanks, no problem, but its really crutch i think)))

In a newer Haxe release, it looks like you can do the following

combinations = split.map (function (value) return Std.parseInt (value));

…but the above is pretty straightforward to understand, and should work on any version

Can’t you do this in the current Haxe release? You should only need the new version for arrow functions.

Also, function (value) return Std.parseInt (value)) is exactly the same as Std.parseInt, so the above can be simplified to this:

combinations = split.map (Std.parseInt);
1 Like