SA-MP Forums Archive
Variable length - 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: Variable length (/showthread.php?tid=105295)



Variable length - loleteviejo - 28.10.2009

How can I know the length of an int variable?
Ex.: PlayerInfo[playerid][pLevel]

I've tried with: new levelength = strlen(PlayerInfo[playerid][pLevel]);
Also: new levelength = sizeof(PlayerInfo[playerid][pLevel]);

But it doesn't work.

Thanks


Re: Variable length - woot - 28.10.2009

The length? Don't you mean the value?
If you mean length, use strlen. (string length)

pawn Код:
new
    tmpString[ 64 ];
   
    format( tmpString, sizeof( tmpString ), "%d", PlayerInfo[playerid][pLevel] );
    format( tmpString2, sizeof( tmpString2 ), "%d", strlen(tmpString) );
    print( tmpString2 );



Re: Variable length - loleteviejo - 28.10.2009

I need to count the characters in PlayerInfo[playerid][pLevel].

In example:
PlayerInfo[playerid][pLevel] = 128

I need a way to know that this variable have 3 digits (1,2, -> [Length] = 3;

It's possible?

Sorry for my english.


Re: Variable length - woot - 28.10.2009

Yep, that's what the "snippet" I posted does.


Re: Variable length - dice7 - 28.10.2009

Use valstr and then strlen

https://sampwiki.blast.hk/wiki/Scripting...ons_Old#valstr
https://sampwiki.blast.hk/wiki/Scripting...ons_Old#strlen