Nifflas' Support Forum

Released Games => Knytt Stories => Topic started by: Polana on June 25, 2012, 22:36:37

Title: Why 255 ?
Post by: Polana on June 25, 2012, 22:36:37
Hi,
I always wonder, why there 255 tilesets, 255 gradients, 255 banks of objects, etc. in the editor. Why not 250 or 300 or some other "round" number ? Is it something in the program ?
Title: Re: Why 255 ?
Post by: LPChip on June 25, 2012, 23:39:34
there are 256, because it goes from 0 to 255.

256 is a value that in the computer world is called a byte. You have a value that has 256 unique possibilities, so you can use one byte per item to keep it the most simple. Otherwise, you have to combine 2 bytes and that involves math. True, also more possibilities, but also a bigger file.

Also: http://256.com/256.html
Title: Re: Why 255 ?
Post by: Threrra on June 25, 2012, 23:46:40
Actually, it's 256 distinct numbers because "0" is a number, too.
A computer uses binary digits, 1 and 0. If you have 1 byte = 8 bits, your smallest binary number is 0000 0000, and your biggest number is 1111 1111 (=>2^8-1, or  255 in decimal systems).
So the index system in the editor uses a single byte to store indices.

300 in decimal becomes 1 0010 1100 in binary. It would have  9 bits instead of 8, but you can't just take single additional bits from your memory, because your memory is organized in bytes. You would need two bytes to handle a number as big as 300.
Then again with two bytes, you would have 65536(=2^16) different numbers. Altough you could force your program to reject numbers that are bigger than 300, there would be no logical reason to restrict it to 300

And 250 becomes 1111 1010. My computer doesn't think it's a "round" number  :^^:

Edit:LPChip beat me to it :(
Title: Re: Why 255 ?
Post by: Raicuparta on June 26, 2012, 13:38:29
If you look closely you will find this kind of limitation in many other games, like the 255 rupee limit in The Legend of Zelda. 8-bit videogames are a great example because they often struggled with memory problems.
Title: Re: Why 255 ?
Post by: Polana on June 26, 2012, 19:17:22
Thank you.
How could I forgot about zero! With 256 it makes perfect sense. I should think more before I ask about something.
Title: Re: Why 255 ?
Post by: Green Moon 93 on October 20, 2012, 21:23:39
Actually, it reminds me quite a lot of 256 colours. Even though it seems a bit off-topic, they both seem very similar.
Title: Re: Why 255 ?
Post by: Yoeri on October 20, 2012, 22:17:27
Actually, it reminds me quite a lot of 256 colours. Even though it seems a bit off-topic, they both seem very similar.
It is. 256 (and 255, for that matter) is a very common number in computing, for the exact reason LPChip mentioned.