String size problem -
Dan. - 13.07.2012
pawn Код:
stock UpdateStatsTextdraw(playerid)
{
new ratio[128];
TextDrawSetString(Textkills[playerid], PlayerInfo[playerid][pKills]);
TextDrawSetString(Textdeaths[playerid], PlayerInfo[playerid][pDeaths]);
ratio[128] = (PlayerInfo[playerid][pKills]/PlayerInfo[playerid][pDeaths]);
TextDrawSetString(Textratio[playerid], ratio);
}
And the error is:
pawn Код:
error 032: array index out of bounds (variable "ratio")
On the line:
pawn Код:
ratio[256] = (PlayerInfo[playerid][pKills]/PlayerInfo[playerid][pDeaths]);
Re: String size problem -
Kirollos - 13.07.2012
uhm..
pawn Код:
stock UpdateStatsTextdraw(playerid)
{
new ratio[128];
TextDrawSetString(Textkills[playerid], PlayerInfo[playerid][pKills]);
TextDrawSetString(Textdeaths[playerid], PlayerInfo[playerid][pDeaths]);
ratio = PlayerInfo[playerid][pKills] / PlayerInfo[playerid][pDeaths];
TextDrawSetString(Textratio[playerid], ratio);
}
i am not sure about this but try
Re: String size problem -
AndreT - 13.07.2012
There's no need to make an array to store the player's kill-death ratio. It needs to be a simple integer (so it will display 5 for example) or a float (so it will display 5.21 for example).
To do this, you need to do:
pawn Код:
new Float:ratio = floatdiv(PlayerInfo[playerid][pKills]/PlayerInfo[playerid][pDeaths]);
What you need to keep in mind:
1. Ratio is a floating point number, so must be a float (Float: tag), not a string. Also if you were to create an array like "new ratio[128];", there's no way you can do "ratio[128]" to access it, the most you can use is "ratio[127]" due to indexes starting from zero (0).
2. Using floatdiv will give you results like 5.21, not 5.
Re: String size problem -
Dan. - 13.07.2012
If the result would be 3,33333333333333333, how can I edit, so it would show 3.33 only?
Also:
pawn Код:
error 035: argument type mismatch (argument 2)
on line:
pawn Код:
TextDrawSetString(Textratio[playerid], ratio);
There is nothing like TextDrawSetFloat, so how to do this?
Re: String size problem -
Vince - 13.07.2012
Format it.
pawn Код:
new text[12]; // longest an integer can be is 11 characters, not sure about floats though
format(text, sizeof(text), "%.2f", ratio);
TextDrawSetString(Textratio[playerid], text);
Re: String size problem -
Dan. - 13.07.2012
Thanks for helping.