This one drives me crazy. It must be something stupid simple, but I can't get my head around it.
I have a function shuffle with three params. Params(1) and Params(2) are the boundaries for a random number. Simple:
set randomPiece to round( random(shuffle.Param(1), shuffle.Param(2) ) )[/code:2ng7jv49]
The following should work too, but they don't:
[code:2ng7jv49]set randomPiece to int( random(shuffle.Param(1), shuffle.Param(2) ) )
set randomPiece to floor( random(shuffle.Param(1), shuffle.Param(2) ) )
The game simply doesn't start (black screen) and I get sometimes a browser error "Uncaught TypeError: Cannot read property 'current_even ' of undefined" and I event can't close the browser window.
The function has a inner condition and calls itself in case the new random number is the same than the given shuffle.Params(0) param:
[b]Why is int() and floor() not working for me?[/b]
Edit: if I deactivate the inner condition (event 8) int() and floor() work
Develop games in your browser. Powerful, performant & highly capable.
My guess is that C2 does not do all the conditions sequentially (the logical way), it does everything at the same time. So basically randomPiece at 7 is NOT computed before the condition 8 is tested.
You should add wait to do anything in order you like...
To use int or floor, you need to add one to the second parameter, or that number will never be reached, as it is exclusive, not inclusive.
So, int( random(shuffle.Param(1), shuffle.Param(2) + 1) )