Posts: 547
Threads: 57
Joined: Dec 2010
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)
Posts: 547
Threads: 57
Joined: Dec 2010
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
Posts: 547
Threads: 57
Joined: Dec 2010
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.
Posts: 547
Threads: 57
Joined: Dec 2010
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.
Posts: 4,759
Threads: 33
Joined: Dec 2013
Reputation:
0
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.
Posts: 547
Threads: 57
Joined: Dec 2010
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)?
Posts: 547
Threads: 57
Joined: Dec 2010
Oh alright, I'll try that and get back to you with the results.
Posts: 547
Threads: 57
Joined: Dec 2010
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