Get the full commented source code of

HTML5 Suika Watermelon Game

Talking about Actionscript 3 and Flash.

Today I was preparing a couple of new tutorials when I found an uint glitch in AS3.

Take this code:

var a:uint=0;
a--;
trace(a);

test it and in your output window you will see 4294967295 because it’s the maximum unsigned integer representable.

Try this code

var a:uint=0;
a--;
trace(a);
trace(uint.MAX_VALUE);

and you will see 4294967295 twice. And that’s ok, because you are trying to represent a negative value with an unsigned integer which can have only positive values, so the result backflips to the highest integer

Now try

var a:uint=0;
a-=uint.MAX_VALUE;
trace(a);

It will print 1, so to check if a number can backflip twice, try

var a:uint=0;
a-=uint.MAX_VALUE+2;
trace(a);

and you’ll get 4294967295 again. That’s right. The number did another backflip.

Now try

var a:uint=0;
a=1/0-1;
trace(a);

And you will get 0. But with

var a:uint=0;
a=1/0;
a-=1;
trace(a);

You will get 4294967295. Obviously nothing different happens if you write

var a:uint=0;
a=(1/0)-1;
trace(a);

A strange way to queue operators in my opinion…

Never miss an update! Subscribe, and I will bother you by email only when a new game or full source code comes out.