Section 4: Variable Constants and Data Types

What are variables and constants?
Variables and constants are one of the most important basic concepts in computer languages ​​(any language). To interpret them literally, variables are something that can change constantly, while constants are fixed and unchangeable. The basic concepts of variables and constants In fact, that's it.

(As shown in the figure: The upper limit of the life value of the little monster in the game is 100, no matter how many times we play it, it is 100, which means it will not change. Then the upper limit of the monster’s life value is a constant, not a variable, because it will not Variety.)

(But the current life value of the little monster is changing, it will decrease with the player's attack, so it is a variable, because it can change. If it becomes a constant, then it means that the monster is invincible)
Insert picture description here
What is the data type?

We already know the basic concepts of variables and constants, so here comes the problem. Since a variable is something that can change constantly, what exactly does that variable change? Is it a number? Or is it a string? Here we have to understand the data types in the program.

Whether in games or other software, variables and constants can be said to be ubiquitous. It can be said that it is almost impossible to have program software that does not use variables (does not rule out software that uses constants completely).

The life value of a monster is a variable, and the attack power of a monster is a variable, the player's level, gold coins, experience value, player name... and so on. As long as it can be changed, it must be a variable. Although they are all variables that can be changed, there are some differences.

For example, the name of the player and the level of the game. The level of the player can be improved by clearing the game, buying experience card acceleration, buying props, etc. The player most intuitively sees that the level number in the game has changed. The player's name can be changed by rename card, but the change is not those Arabic numerals, but the "player name" next to your avatar.

This is the most intuitive example of two variable changes. They are both variables, but their data types are different. The game level uses numbers, and the player names use "words". To understand how they are different, we need to know the data types in the language.

Integers: First of all, let's first understand, what is an integer?

Integers are the numbers we usually see. We have never seen the weird levels of "12.3, 35.4" in the game. What we can see is only level 12, level 20, level 54 and so on. Because in the game, the data type of the level is an integer, that is, a number without a decimal point. This is an integer. In professional terms, an integer is called an integer.

Real numbers: First of all, let's first understand what is a real number?

Real numbers are the same as the above integers, integers do not have a decimal point, and real numbers do. 12.2, 98.6, 66.21 and so on. These are real numbers. Real numbers are called floating-point numbers in technical terms.

Characters: First of all, let's first understand what is a character?

Numbers, letters, words, symbols, etc. are all characters, such as 8, H, h, country, & etc. A character is a word, remember, there is only one word! (Neither word will work) This word may be a number, a letter, or a symbol. Characters are also a common type of data.

String: So, what is a string?

w is a character, 3, c, s, c, h, o are all characters, now I connect these characters, w3cscho is a string consisting of 7 characters, the string is simply a lot of strings Up.

These 4 data types are just the most common ones, and there are other types that are not listed here. So now it's easy to understand the player's name and player level. The player level is obviously an integer, which is definitely not a real number. The name of a player is generally impossible to have only one character, so excluding characters, then the name of the player is naturally a string.

(End of this section)

Guess you like

Origin blog.csdn.net/weixin_45213735/article/details/103260330