Variable..
#1

This sum score:
pawn Код:
PlayerInfo[playerid][score]++;
What but how do I add a number ? Example +10

What would be as well ?
pawn Код:
PlayerInfo[playerid][score]+10;
Reply
#2

What you wanna to do plz explain it briefly
Reply
#3

PHP код:
//Add 10 to the player's score.
PlayerInfo[playerid][score] += 10
which is the same as

PHP код:
//Add 10 to the player's score.
PlayerInfo[playerid][score] = (PlayerInfo[playerid][score] + 10); 
So, a += 1 or a = (a + 1) is the same as a++!

The difference here is that a + b is an arithmetic expression and not a statement. a + b will yield the result of a + b, but a += b will assign the value of a + b to a. This means "+=" just adds the value to the variable on the left hand side and stores it.

An example of it in use:

PHP код:
//Declare a and b
new 5;
new 
3;
//Add 3 to 5, put in a
+= b;
//This would print out 8.
printf("%d"a); 
Another thing to note about this operator is that like most other operators, it can be "chained" in sequence, which comes in handy sometimes:

PHP код:
//Declare a, b and c.
new 5,
    
3,
    
6;
//Add C to B, and add B to A
+= += c;
//Print out result. We should get 14 (5 + (6 + 3))
printf("%d"a); 
which is the same as

PHP код:
//Declare a, b and c.
new 5,
    
3,
    
6;
//Set a to (a + b + c)
= (c);
//Print out a. We should get 14 (5 + 3 + 6).
printf("%d"a); 
Reply
#4

Quote:
Originally Posted by blewert
Посмотреть сообщение
PHP код:
//Add 10 to the player's score.
PlayerInfo[playerid][score] += 10
which is the same as

PHP код:
//Add 10 to the player's score.
PlayerInfo[playerid][score] = (PlayerInfo[playerid][score] + 10); 
So, a += 1 or a = (a + 1) is the same as a++!

The difference here is that a + b is an arithmetic expression and not a statement. a + b will yield the result of a + b, but a += b will assign the value of a + b to a. This means "+=" just adds the value to the variable on the left hand side and stores it.

An example of it in use:

PHP код:
//Declare a and b
new 5;
new 
3;
//Add 3 to 5, put in a
+= b;
//This would print out 8.
printf("%d"a); 
Another thing to note about this operator is that like most other operators, it can be "chained" in sequence, which comes in handy sometimes:

PHP код:
//Declare a, b and c.
new 5,
    
3,
    
6;
//Add C to B, and add B to A
+= += c;
//Print out result. We should get 14 (5 + (6 + 3))
printf("%d"a); 
which is the same as

PHP код:
//Declare a, b and c.
new 5,
    
3,
    
6;
//Set a to (a + b + c)
= (c);
//Print out a. We should get 14 (5 + 3 + 6).
printf("%d"a); 
Thanks
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)