PlayerTextDrawSetString
#1

I've ran into a problem where I can't specify the player textdraw I want to update with a formatted string.

pawn Код:
public AssignInventoryNameValues(playerid)
{
    for(new i=0; i<MAX_INVSLOTS; i++)
    {
        new txt[32],string[128];
        switch(IsStackableItemInPlayerSlot(playerid,i))
        {
            case 0: format(string,sizeof(string),"%i. %s",i+1,GetItemName(playerid,i));
            case 1: format(string,sizeof(string),"%i. %s (%i)",i+1,GetItemName(playerid,i),Player[playerid][pInventoryAmount][i]);
        }
        format(txt,sizeof(txt),"InvSlot%i[playerid]",i+1);
        PlayerTextDrawSetString(playerid,txt,string); //this is the error line
    }
    return 1;
}
When I compile all I get for the error is:
pawn Код:
error 035: argument type mismatch (argument 2)
Reply
#2

According to this https://sampwiki.blast.hk/wiki/PlayerTextDrawSetString the
Код:
PlayerTextDrawSetString(playerid,txt,string);
"txt" need to replaced with the textdraw and yeah i think the format line
Код:
format(txt,sizeof(txt),"InvSlot%i[playerid]",i+1);
the "txt" should be replaced with "string". Try it i'm not sure about this.
Reply
#3

Quote:
Originally Posted by DTV
Посмотреть сообщение
I've ran into a problem where I can't specify the player textdraw I want to update with a formatted string.

pawn Код:
public AssignInventoryNameValues(playerid)
{
    for(new i=0; i<MAX_INVSLOTS; i++)
    {
        new txt[32],string[128];
        switch(IsStackableItemInPlayerSlot(playerid,i))
        {
            case 0: format(string,sizeof(string),"%i. %s",i+1,GetItemName(playerid,i));
            case 1: format(string,sizeof(string),"%i. %s (%i)",i+1,GetItemName(playerid,i),Player[playerid][pInventoryAmount][i]);
        }
        format(txt,sizeof(txt),"InvSlot%i[playerid]",i+1);
        PlayerTextDrawSetString(playerid,txt,string); //this is the error line
    }
    return 1;
}
When I compile all I get for the error is:
pawn Код:
error 035: argument type mismatch (argument 2)
It's because PlayerTextDrawSetString must have 3 parameters. playerid, textname, textdrawstring.
Is the second parameter a textdraw variable?
Reply
#4

Quote:
Originally Posted by vassilis
Посмотреть сообщение
It's because PlayerTextDrawSetString must have 3 parameters. playerid, textname, textdrawstring.
Is the second parameter a textdraw variable?
See he just made it like this new txt[32] which easily prooves that it isn't textdraw. That's what i'm saying that change it into a textdraw.
Reply
#5

Sorry for not clarifying, I do have the textdraw variables towards the top of the script:

pawn Код:
// ---Player Textdraws---
new PlayerText:InvBox[MAX_PLAYERS],PlayerText:InvAmount[MAX_PLAYERS],PlayerText:InvSlot1[MAX_PLAYERS],PlayerText:InvSlot2[MAX_PLAYERS],PlayerText:InvSlot3[MAX_PLAYERS];
//other textdraw variables
Reply
#6

Код:
format(string,sizeof(string),"InvSlot%i[playerid]",i+1);
PlayerTextDrawSetString(playerid,InvBox,string);
Try it and tell me
Reply
#7

Quote:
Originally Posted by Sunehildeep
Посмотреть сообщение
Код:
format(string,sizeof(string),"InvSlot%i[playerid]",i+1);
PlayerTextDrawSetString(playerid,InvBox,string);
Try it and tell me
That won't work. If you look at the code, you can see that the string is already being formatted for something else, so it can't be used and thus why I have the txt string there.
Reply
#8

Didn't saw that. Try this.
Код:
format(txt,sizeof(txt),"InvSlot%i[playerid]",i+1);
PlayerTextDrawSetString(playerid,InvBox,string); // InvBox is the textdraw being used here. The second value in this line must be always a textdraw or it will return with argument error
Reply
#9

Quote:
Originally Posted by Sunehildeep
Посмотреть сообщение
Didn't saw that. Try this.
Код:
format(txt,sizeof(txt),"InvSlot%i[playerid]",i+1);
PlayerTextDrawSetString(playerid,InvBox,string); // InvBox is the textdraw being used here. The second value in this line must be always a textdraw or it will return with argument error
I still don't see how this would work at all, the txt string isn't being used in this example so it's useless, not to mention InvBox would just show up as being an invalid variable.
Reply
#10

You're doing it wrong, use one array and instead of InvSlot%d, it will be InvSlot[%d]. You can't use a variable that stores a string, as an integer with the wrong tag.
Reply
#11

Quote:
Originally Posted by SickAttack
Посмотреть сообщение
You're doing it wrong, use one array and instead of InvSlot%d, it will be InvSlot[%d]. You can't use a variable that stores a string, as an integer with the wrong tag.
So instead of having it like PlayerText:InvSlot1[playerid],PlayerText:InvSlot2[playerid] (so on and so forth), you mean have it like PlayerText:InvSlot[x] (x being the number)?
Reply
#12

InvSlot[playerid][x]
Reply
#13

Oh alright, I'll try that and get back to you with the results.
Reply
#14

Hmm, it still has the same error.

EDIT: Nevermind, I still tried formatting when I realized I didn't need to, thanks for the help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)