String size problem
#1

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]);
Reply
#2

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
Reply
#3

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.
Reply
#4

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?
Reply
#5

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);
Reply
#6

Thanks for helping.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)