SA-MP Forums Archive
explanation - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: explanation (/showthread.php?tid=611796)



explanation - iKevin - 10.07.2016

Hey if I have a variable and I type like this in a function
Код:
...
SomeVar[somevar]++;
..
What does the ++ do? Can we make something else instead of that ++?


Re: explanation - Gammix - 10.07.2016

This adds +1 to the variable.

Here are different instances of using ++:
pawn Код:
// SomeVar[somevar] is 0

SomeVar[somevar]++;

// SomeVar[somevar] will be 1 now



// SomeVar[somevar] is 0

++SomeVar[somevar];

// SomeVar[somevar] will be 1 now
pawn Код:
// SomeVar[somevar] is 0

printf("%i", SomeVar[somevar]++);

// System will print "0" but SomeVar[somevar] is "1" (SomeVar[somevar] value is taken first and then +1 is added)


pawn Код:
// SomeVar[somevar] is 0

printf("%i", ++SomeVar[somevar]);

// System will print "1" and SomeVar[somevar] is "1" as well (+1 is added first and then SomeVar[somevar] is taken)



Re: explanation - iKevin - 10.07.2016

Thanks.


Re: explanation - yutaruta - 11.07.2016

Instead of ++ you can do

Somevar[somevar] = Somevar[somevar] + 1;

or also

Somevar[somevar] += 1;