PDA

View Full Version : Help with string size.


m1kas
09/03/2018, 04:37 PM
Hey, so recently I've started to make an end round score box, which displays player names, score, kills and damage, however when creating it it shows its an unknown command, the string sizes are all 256.

new AttList[256], AttKills[256], AttScore[256], AttDamage[256], DefList[256], DefKills[256], DefScore[256], DefDamage[256], TopScore[256];

However when I change the string sizes to 10 they all work fine, however I need more than 10 cells for each one. What's the problem here?

jasperschellekens
09/03/2018, 04:47 PM
what about showing the entire command?

m1kas
09/03/2018, 04:53 PM
CMD:list(playerid, params[])
{
new playerScores[MAX_PLAYERS][rankingEnum], index, p;

foreach(new i : Player)
{
if(PlayerInfo[i][pWasInArena])
{
playerScores[index][player_Score] = floatround(PlayerInfo[i][pDamage]);
playerScores[index++][player_ID] = i;
p++;
}
}

GetPlayerHighestScores(playerScores, 0, (index-1));

new AttList[256], AttKills[256], AttScore[256], AttDamage[256], DefList[256], DefKills[256], DefScore[256], DefDamage[256], TopScore[256];

for(new i = 0; i != p; i++)
{
if(IsPlayerAttacker(playerScores[i][player_ID]))
{
format(AttList, sizeof(AttList), "%s~r~~h~%s~n~", AttList, GetPlayerNameEx(playerScores[i][player_ID]));
format(AttKills, sizeof(AttKills), "%s~w~~h~~h~%d~n~", AttKills, PlayerInfo[playerScores[i][player_ID]][pRoundKills]);
format(AttScore, sizeof(AttScore), "%s~w~~h~~h~%d~n~", AttScore, PlayerInfo[playerScores[i][player_ID]][pRoundPoints]);
format(AttDamage, sizeof(AttDamage), "%s~w~~h~~h~%d~n~", AttDamage, playerScores[i][player_Score]);
}
else if(IsPlayerDefender(playerScores[i][player_ID]))
{
format(DefList, sizeof(DefList), "%s~b~~h~%s~n~", DefList, GetPlayerNameEx(playerScores[i][player_ID]));
format(DefKills, sizeof(DefKills), "%s~w~~h~~h~%d~n~", DefKills, PlayerInfo[playerScores[i][player_ID]][pRoundKills]);
format(DefScore, sizeof(DefScore), "%s~w~~h~~h~%d~n~", DefScore, PlayerInfo[playerScores[i][player_ID]][pRoundPoints]);
format(DefDamage, sizeof(DefDamage), "%s~w~~h~~h~%d~n~", DefDamage, playerScores[i][player_Score]);
}

if(i == 0) format(TopScore, sizeof(TopScore), "%s%s1. %s~n~", TopScore, IsPlayerAttacker(playerScores[i][player_ID]) ? ("~r~") : ("~b~"), GetPlayerNameEx(playerScores[i][player_ID]));
else if(i == 1) format(TopScore, sizeof(TopScore), "%s%s2. %s~n~", TopScore, IsPlayerAttacker(playerScores[i][player_ID]) ? ("~r~") : ("~b~"), GetPlayerNameEx(playerScores[i][player_ID]));
else if(i == 2) format(TopScore, sizeof(TopScore), "%s%s3. %s~n~", TopScore, IsPlayerAttacker(playerScores[i][player_ID]) ? ("~r~") : ("~b~"), GetPlayerNameEx(playerScores[i][player_ID]));
}

TextDrawSetString(attackerText[0], AttList);
TextDrawSetString(attackerText[2], AttKills);
TextDrawSetString(attackerText[1], AttScore);
TextDrawSetString(attackerText[3], AttDamage);
TextDrawSetString(defenderText[0], DefList);
TextDrawSetString(defenderText[2], DefKills);
TextDrawSetString(defenderText[1], DefScore);
TextDrawSetString(defenderText[3], DefDamage);
TextDrawSetString(topList, TopScore);

for(new i = 0; i < 15; i++)
{
TextDrawShowForAll(endText[i]);
}
for(new i = 0; i < 4; i++)
{
TextDrawShowForAll(attackerText[i]);
}
for(new i = 0; i < 4; i++)
{
TextDrawShowForAll(defenderText[i]);
}

TextDrawShowForAll(topList);

return 1;
}



Like I mentioned previously, by lowering the string size everything works, so I doubt that's the problem

Meller
09/03/2018, 05:15 PM
Your code is literaly making me cry. Learn how to format your code for better compability, stability and mobility. Start off with removing all of those variables and only use a single one, consider making it dynamic as well if you so need. Writing a plain and simple '256' cells doesn't help you at all, what if some variables exceed 256? Make it dynamic mate.

m1kas
09/03/2018, 05:25 PM
Do you mind giving an example? I don't see another way besides looping 16 times instead of the one, if you could help me that would be very appreciated and it's the reason I posted here

Meller
09/03/2018, 05:31 PM
Do you mind giving an example? I don't see another way besides looping 16 times instead of the one, if you could help me that would be very appreciated and it's the reason I posted here

Giving you an example isn't how scripting works, learn from documentation. This is a scripting 'help' forum, not a scripting 'request' forum. Read the PAWN3 PDF language documentation.

m1kas
09/03/2018, 05:40 PM
Giving you an example isn't how scripting works, learn from documentation. This is a scripting 'help' forum, not a scripting 'request' forum. Read the PAWN3 PDF language documentation.

I'm not asking you to script anything, I'm just wondering how do you transform 9 completely different strings into one and successfully get every textdraw string to be formatted in one loop.

Meller
09/03/2018, 05:41 PM
You do realize you've got like 5 IF statements? ...

m1kas
09/03/2018, 05:44 PM
for(new i = 0; i != p; i++)
{
if(IsPlayerAttacker(playerScores[i][player_ID]))
{
format(AttList, sizeof(AttList), "%s~r~~h~%s~n~", AttList, GetPlayerNameEx(playerScores[i][player_ID]));
format(AttKills, sizeof(AttKills), "%s~w~~h~~h~%d~n~", AttKills, PlayerInfo[playerScores[i][player_ID]][pRoundKills]);
format(AttScore, sizeof(AttScore), "%s~w~~h~~h~%d~n~", AttScore, PlayerInfo[playerScores[i][player_ID]][pRoundPoints]);
format(AttDamage, sizeof(AttDamage), "%s~w~~h~~h~%d~n~", AttDamage, playerScores[i][player_Score]);
}
else if(IsPlayerDefender(playerScores[i][player_ID]))
{
format(DefList, sizeof(DefList), "%s~b~~h~%s~n~", DefList, GetPlayerNameEx(playerScores[i][player_ID]));
format(DefKills, sizeof(DefKills), "%s~w~~h~~h~%d~n~", DefKills, PlayerInfo[playerScores[i][player_ID]][pRoundKills]);
format(DefScore, sizeof(DefScore), "%s~w~~h~~h~%d~n~", DefScore, PlayerInfo[playerScores[i][player_ID]][pRoundPoints]);
format(DefDamage, sizeof(DefDamage), "%s~w~~h~~h~%d~n~", DefDamage, playerScores[i][player_Score]);
}
}


Those are the only essential ones that I'm asking about how do you transform those 8 different strings into one and loop it once.

NaS
10/03/2018, 01:10 AM
The reason for the "Unknown Command" message could be because you use many big arrays.
That's 8 times 256 cells plus the playerScores array which is at least 2 * 1000 cells.

These are declared locally so there isn't unlimited space.

Try to assemble each string for each textdraw seperately, like this:

- loop with format
- textdrawsetstring
- loop with format
- textdrawsetstring

and reuse the string for each of them - remember to clear the string before formatting the next one, simply by doing

string[0] = EOS;

The overhead from 7 additional loops is negligible if working with such big strings anyway. You'll have 7 less big arrays.

The other way would be not to blindly declare them with 256 cells. Calculate how big each of the Arrays can possibly get at maximum number of players and text length for each entry, and declare them based on that.

Also you can save some characters by taking out all the color codes (~r~~h~~h~) etc and use TextDrawColor. You only use one color per TextDraw anyway (you'll save a lot of characters).

m1kas
10/03/2018, 01:37 AM
Thank you so much for your help, got it working!