Skip to content
Locked

Negative value for variable

-migrated-

2 posts

Negative value for variable

Posted Aug 7, 2011 5:26 am

I came across a game where variable is declared with negative value

Code: [Select]

selectedLevel:int = -1;
what does it mean

Re: Negative value for variable

Posted Aug 7, 2011 6:24 am

it means that the value is less than 0...

developers (read: "I") typically use negative values as -- generally binary -- semaphores.  This way I can essentially have a flag variable without the resource overhead of an actual additional variable.

in your example it logically means that "no level has _actually_ been selected, so don't run the level selection routines."

I use this AoB tool to make all the AoBs I post. Try the online version if you dont feel like downloading it.
"Obviously, windows are central to Windows. They are so important that they named the operating system after them. But what is a window?"

This topic is locked.