How would I go about setting a colour as a string? -
2KY - 24.04.2012
Inside of my user files, colours are saved like so;
So what I'm trying to do is..
pawn Код:
format( colStr, sizeof( colStr ), "0x%sFF", accInfo [ playerid ] [ Colour ] );
SetPlayerColor( playerid, colStr );
How would I go about doing this?
Re: How would I go about setting a colour as a string? -
iRage - 24.04.2012
You'll have to create an enum for accInfo.
PHP код:
enum playerenum
{
Colour
}
new accInfo[MAX_PLAYERS][playerenum];
Assign it a value.
PHP код:
accInfo[playerid][Colour] = FFFFFF
Then the code you inserted would work perfectly.
PHP код:
new colStr[12];
format( colStr, sizeof( colStr ), "0x%sFF", accInfo [ playerid ] [ Colour ] );
SetPlayerColor( playerid, colStr );
Re: How would I go about setting a colour as a string? -
2KY - 24.04.2012
Quote:
Originally Posted by iRage
You'll have to create an enum for accInfo.
PHP код:
enum playerenum
{
Colour
}
new accInfo[MAX_PLAYERS][playerenum];
Assign it a value.
PHP код:
accInfo[playerid][Colour] = FFFFFF
Then the code you inserted would work perfectly.
PHP код:
new colStr[12];
format( colStr, sizeof( colStr ), "0x%sFF", accInfo [ playerid ] [ Colour ] );
SetPlayerColor( playerid, colStr );
|
I've got all of that, and that's EXACTLY what I have. You can't set a colour as a string like that.
Quote:
newmode.pwn(295) : error 035: argument type mismatch (argument 2)
|
Re: How would I go about setting a colour as a string? -
Marco_Valentine - 24.04.2012
two people making this mistake..
just use:
Код:
SetPlayerColor( playerid, accInfo [ playerid ] [ Colour ] );
Re: How would I go about setting a colour as a string? -
2KY - 24.04.2012
Quote:
Originally Posted by Marco_Valentine
two people making this mistake..
just use:
Код:
SetPlayerColor( playerid, accInfo [ playerid ] [ Colour ] );
|
I suppose I'll just modify my file-write to 0xFFFFFFFF rather than just FFFFFFF.
Respuesta: How would I go about setting a colour as a string? -
OPremium - 24.04.2012
Use sscanf or try hexstr by ******:
pawn Код:
stock hexstr(string[])
{
new
ret,
val,
i;
if (string[0] == '0' && (string[1] == 'x' || string[1] == 'X')) i = 2;
while (string[i])
{
ret <<= 4;
val = string[i++] - '0';
if (val > 0x09) val -= 0x07;
if (val > 0x0F) val -= 0x20;
if (val < 0x01) continue;
if (val < 0x10) ret += val;
}
return ret;
}
-------------------------------------------------------------------------------------------
Quote:
Originally Posted by 2KY
Quote:
Originally Posted by Marco_Valentine
two people making this mistake..
just use:
Код:
SetPlayerColor( playerid, accInfo [ playerid ] [ Colour ] );
|
I suppose I'll just modify my file-write to 0xFFFFFFFF rather than just FFFFFFF.
|
It would still be an string!
Re: Respuesta: How would I go about setting a colour as a string? -
2KY - 24.04.2012
Quote:
Originally Posted by OPremium
Use sscanf or try hexstr by ******:
pawn Код:
stock hexstr(string[]) { new ret, val, i; if (string[0] == '0' && (string[1] == 'x' || string[1] == 'X')) i = 2; while (string[i]) { ret <<= 4; val = string[i++] - '0'; if (val > 0x09) val -= 0x07; if (val > 0x0F) val -= 0x20; if (val < 0x01) continue; if (val < 0x10) ret += val; } return ret; }
-------------------------------------------------------------------------------------------
It would still be an string! 
|
Oddly enough it still works.