SA-MP Forums Archive
Filling a String - 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)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Filling a String (/showthread.php?tid=170352)



Filling a String - Nonameman - 22.08.2010

Hey all!

I want to create a dialog, where I'll put a lot of informations, and after every 10th information start the next in a new line. I created a for cycle, which fills up the string with the infos, so now I just need a function that returns true, if 'variable/10 == integer' and returns false, if it's float.

How to do it?

Thanks
Nonameman


Re: Filling a String - CJ101 - 22.08.2010

Heres a example.

Код:
new string[128];
format(string,sizeof string,"Something");
format(string,sizeof string,"%s\nLine 2",string);
If im not mistaken thats what you want...

The final string will be:

Код:
Something
Line2



Re: Filling a String - Nonameman - 22.08.2010

I know how to make a new line, what I want is a function, the integer/float checker


Re: Filling a String - pyrodave - 22.08.2010

Try this, its untested but I see no reason for it not to work:

pawn Код:
stock IsDivTen(val)
{
    return (val % 10)?(false):(true);
}



Re: Filling a String - Nonameman - 22.08.2010

Thanks, can You show me how is it works
Код:
return (val % 10)?(false):(true);
, because I've never seen someting like this


Re: Filling a String - pyrodave - 22.08.2010

The % operator is called the modulus operator (nothing like the mathematical modulus like |-5| = 5).

It will return the remainder of a division, so if you do:
pawn Код:
20 % 10
It will return 0, because 20 goes into 10 twice, with 0 remainder.

However if you do:
pawn Код:
21 % 10
It will return 1, because 21 can be divided into 10 twice (the 20) and then theres 1 remainder.

The ? and : are triadic operators, so the whole function is basically saying:

"If the return value of 'val % 10' is 0, then return true, if there is any remainder, then return false."

So if you plug a value into that function it will return true if the value is divisible by 10, and return false if its not.

You could also use a macro:

pawn Код:
#define IsDivTen(%1) ((%1) % 10)?(false):(true)



Re: Filling a String - Nonameman - 22.08.2010

Thanks a lot.