changing interger with percent sign - 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: changing interger with percent sign (
/showthread.php?tid=649427)
changing interger with percent sign -
eSPeZet - 08.02.2018
Hello,
I saw some lines in a script and I tried everything to understand it (looked in samp wiki, without any results), used ****** and at the end I kept changing the values to figure out a pattern, but it was hopeless..
I can't figure out what this "%" DOES or means:
Код:
new newstatus = 1;
newstatus %= 2;
if(newstatus == 0)strcat(newname, "test");
Can someone please explain this? What is it and what is it used for?
Re: changing interger with percent sign -
Private200 - 08.02.2018
4 % 2 = 0
5 % 2 = 1
19 % 2 = 1
It returns the value that remains after division (19%2; 18 + [1]; [x] => you get returned that X value)
- Just search for Modulo in any search engine; you will find some interesting stuff:
Код:
(in number theory) with respect to or using a modulus of a specified number. Two numbers are congruent modulo a given number if they give the same remainder when divided by that number.
Re: changing interger with percent sign -
eSPeZet - 08.02.2018
ahhhh I get it now
thank you very much
Where do you get to know such kind of things? If i wouldn't have asked I would have never known
Re: changing interger with percent sign -
AmigaBlizzard - 09.02.2018
G o o g l e is your friend.
Just tried "variable %= 2" in the G o o g l e search-bar and the first page was this one:
https://www.w3schools.com/js/js_operators.asp
Further down, there was the % operator, which means modulus.
And a little further down, it lists this in a table:
%= | x %= y | x = x % y
Search G o o g l e for "modulus" and you'll find countless pages which explain it all.