+ 2

What is the use of integer type variables in game development?

a friend of mine is creating a text based game, and I don't understand what the use of integer type variables would be. can anyone explain?

1st Jun 2017, 10:52 AM
Ray
Ray - avatar
8 odpowiedzi
+ 2
Another use is for storing information. Lets say, for example, a game where you can have armor parts attached. Suppose there are 5 parts, one for each of two legs two arms and torso. The state of the players armor can be expressed asking the questions "does the player have a left leg armor?" and so on for all the armor parts. The question is a yes/no question, so the result can be a 1 or a 0. That can be stored in a bit, we have 5 parts, so 5 bits, which must be stored in a byte (8). b00000001(1 dec): The player has the left arm armor. b00000010(2 dec): The player has the right arm armor. b00000100(4 dec): The player has the left leg armor. b00001000(8 dec): The player has the right leg armor. b00010000(16 dec): The player has the torso armor. So if we have the number b00010101, that would mean that the player has the torso and left arm and leg armor and you can do bitwise operations to combine different armor states in arbitrary ways. But what if there are different armors? Change the base of the number and use each digit for each different armor. An int is a 4byte(32bit) value in most of the systems, so that would give you 32 yes/no answer questions stored in a number.
1st Jun 2017, 2:33 PM
Madera Oxidada
Madera Oxidada - avatar
+ 5
Tons of uses. Every datatype has uses. Like Gorica said, indexing arrays is one of them but even basic stuff like while and for loops are usually incrememted with Integer values. And loops are the most basic structures!
1st Jun 2017, 11:06 AM
Pixie
Pixie - avatar
+ 3
Any data type is necessity for any type of program. It's the basic structure and the way program present and utilise all the data.
1st Jun 2017, 11:07 AM
Calviղ
Calviղ - avatar
+ 2
Hello, one of the examples of use of integer type variables is for indexing of arrays.
1st Jun 2017, 11:02 AM
Gorica Stevanovic
Gorica Stevanovic - avatar
0
thanks for answering me ma'am. but I don't understand. can you please explain a little more?
1st Jun 2017, 11:04 AM
Ray
Ray - avatar
0
got it. thanks for the answers :)
1st Jun 2017, 11:07 AM
Ray
Ray - avatar
0
OK sir
1st Jun 2017, 11:08 AM
Ray
Ray - avatar
0
java
2nd Jun 2017, 5:54 AM
anurag roy
anurag roy - avatar