Text draw won't show after adding an additional color code...
#1

Okay, so here's the deal. I am trying to dynamically list the characters in a faction and put them into a text draw. I ended up with this sliver of code:

pawn Code:
new
    szString[150],
    szFirstName[2],
    szMainString[1000];

foreach(new iTarget : Player)
{
    if(IsPlayerInFactionID(iTarget, pStats[playerid][iPlayerFaction][i]))
    {
        strmid(szFirstName, pStats[iTarget][pFirstName], 0, 1);
        format(szString, sizeof(szString), "~y~%s. %s", szFirstName, pStats[iTarget][pLastName]);
        strcat(szMainString, szString);
        strcat(szMainString, "~w~, "); // this is the problem line
    }
}

strins(szMainString, "Online Members: ", 0);
PlayerTextDrawSetString(playerid, textPlayerFactionList[2], szMainString);
Notice the commented line? Whenever that line is there, the text-draw doesn't show up. However, when I remove it, it works absolutely fine. I don't see a problem with this though because the text-draw only has (at this point) 2 color codes in it.

Does anyone have any idea why the commented line of code (basically) disables the text draw?
Reply
#2

I've suffered through this problems before. The problem is because you leave a blank space after finishing up the list of players.

To solve it, delete the last character after you finish listing all players. So something like:

pawn Code:
strdel(szMainString, strlen(szMainString), strlen(szMainString) - 1);
Reply
#3

Unfortunately, that didn't solve the problem. I tried doing this:

pawn Code:
foreach(new iTarget : Player)
            {
                if(IsPlayerInFactionID(iTarget, pStats[playerid][iPlayerFaction][i]))
                {
                    strmid(szFirstName, pStats[iTarget][pFirstName], 0, 1);
                    format(szString, sizeof(szString), "~y~%s~w~. ~y~%s", szFirstName, pStats[iTarget][pLastName]);
                    strcat(szMainString, szString);
                }
            }
.. and even that didn't work right. There's something with the color codes, but I've never had an issue with them like this before so I'm just not sure why it wouldn't work!
Reply
#4

I'm not an expert in this field, but would it not make more sense to switch these two around?

pawn Code:
strcat(szMainString, szString);
strcat(szMainString, "~w~, "); // this is the problem line
it looks like you're trying to cat the string before it's there?
Like this..
pawn Code:
strcat(szMainString, "~w~, "); // this is the problem line
strcat(szMainString, szString);
Reply
#5

No it has to come after the contents of "szString". I was able to get it working with this:

pawn Code:
foreach(new iTarget : Player)
{
    if(IsPlayerInFactionID(iTarget, pStats[playerid][iPlayerFaction][0]))
    {
        strcat(szMainString, "~w~,");
        format(szString, sizeof(szString), " ~y~%s %s", pStats[iTarget][pFirstName], pStats[iTarget][pLastName]);
        strcat(szMainString, szString);
    }
}
Although it's not really what I wanted. I don't know, perhaps the period ( . ) had something to do with it..?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)