SA-MP Forums Archive
String trouble - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: String trouble (/showthread.php?tid=548819)



String trouble - cnoopers - 02.12.2014

playeritem0 should return string but after use %s is something like ' e []'
what is wrong
Код:
new items[] =
{
	"Phone",
	"Glock"
};
Код:
playeritem0[playerid] = items[1];



Re: String trouble - Raweresh - 02.12.2014

Change:
Код:
new items[] =
To:
Код:
new items[][] =



Re: String trouble - cnoopers - 02.12.2014

now is ' G [] '.


Re: String trouble - Schneider - 02.12.2014

pawn Код:
new items[][] =
{
    "Phone",
    "Glock"
};

new playeritem0[MAX_PLAYERS][24];
pawn Код:
playeritem0[playerid] = items[1];



Re: String trouble - AnthonyTimmers - 02.12.2014

Quote:
Originally Posted by cnoopers
Посмотреть сообщение
playeritem0 should return string but after use %s is something like ' e []'
what is wrong
Код:
new items[] =
{
	"Phone",
	"Glock"
};
Код:
playeritem0[playerid] = items[1];
An array of strings means using [][]


Re: String trouble - cnoopers - 02.12.2014

Код:
error 047: array sizes do not match, or destination array is too small
error 033: array must be indexed (variable "playeritem0")
Код:
playeritem0[playerid] = items[1]; //here first

//in test cmd
if(playeritem0[playerid] == items[1]) //and here second
Код:
new items[][] =
{
    "Phone",
    "Glock"
};

new playeritem0[MAX_PLAYERS][24];



Re: String trouble - Raweresh - 02.12.2014

Change:
Код:
playeritem0[playerid] = items[1];
To:
Код:
format(playeritem0[playerid],sizeof(playeritem0),items[1][0]);



Re: String trouble - Larceny - 02.12.2014

For strings you have to use strcmp to compare. You can give those items IDs and then get their names through the ID.


Re: String trouble - Pottus - 02.12.2014

First issue the array sizes are not the same you will need to use strcat() to copy the string.
Second issue as mentioned use strcmp() to compare strings.

Note: Before copying make sure the string you are copying to is cleared. MyString[0] = '\0';