array must be indexed(variable "-unknown") help
#1

Код:
(20795) : error 033: array must be indexed (variable "-unknown-")
(20796) : error 033: array must be indexed (variable "-unknown-")
(20797) : error 033: array must be indexed (variable "-unknown-")
(20798) : error 033: array must be indexed (variable "-unknown-")
(20799) : error 033: array must be indexed (variable "-unknown-")
(20800) : error 033: array must be indexed (variable "-unknown-")
(20801) : error 033: array must be indexed (variable "-unknown-")
(20803) : error 033: array must be indexed (variable "-unknown-")
(20804) : error 033: array must be indexed (variable "-unknown-")
(20805) : error 033: array must be indexed (variable "-unknown-")
(20806) : error 033: array must be indexed (variable "-unknown-")
(20807) : error 033: array must be indexed (variable "-unknown-")
(20808) : error 033: array must be indexed (variable "-unknown-")
(20809) : error 033: array must be indexed (variable "-unknown-")
(20810) : error 033: array must be indexed (variable "-unknown-")
(20811) : error 033: array must be indexed (variable "-unknown-")
Here's the code
Код:
CMD:port(playerid,params[])
{
		new lokejsn;
		if(sscanf(params,"s",lokejsn)) return SendClientMessage(playerid,COLOR_GREY,"Usage: /port [location]");
		if(!sscanf(params,"s",lokejsn))
		{
    	        if(lokejsn == "1") { JBC_SetPlayerPos(playerid,1819.2871,-2066.6099,13.3828); }
		if(lokejsn == "2")  { JBC_SetPlayerPos(playerid,2248.4661,-2206.4880,13.5469); }
		if(lokejsn == "3")  { JBC_SetPlayerPos(playerid,2635.6763,-1055.4916,69.6262); }
		if(lokejsn == "4")  { JBC_SetPlayerPos(playerid,2039.8297,-1334.1455,23.9844); }
		if(lokejsn == "5")  { JBC_SetPlayerPos(playerid,1536.1923,-1685.3463,13.5469); }
		if(lokejsn == "6") { JBC_SetPlayerPos(playerid,922.9431,-985.4662,38.3301); }
		if(lokejsn == "7")  { JBC_SetPlayerPos(playerid,1189.4653,-1327.3873,13.5677); }
		if(lokejsn == "8")  { JBC_SetPlayerPos(playerid,1584.7924,-2311.3904,13.5469); }
		if(lokejsn == "9")  { JBC_SetPlayerPos(playerid,1678.8199,1475.2837,10.7638); }
		if(lokejsn == "10")  { JBC_SetPlayerPos(playerid,-1422.8849,-292.1181,14.1484); }
		if(lokejsn == "11")  { JBC_SetPlayerPos(playerid,2763.1379,-2403.0957,13.6328); }
		if(lokejsn == "12")  { JBC_SetPlayerPos(playerid,1221.9834,-926.6932,42.8429); }
		if(lokejsn == "13")  { JBC_SetPlayerPos(playerid,554.7620,-1265.9377,17.2422); }
		if(lokejsn == "14")  { JBC_SetPlayerPos(playerid,1467.1404,-1738.6975,13.5469); }
		if(lokejsn == "15")  { JBC_SetPlayerPos(playerid,1456.6160,-1027.7120,23.8281); }
		if(lokejsn == "16")  { JBC_SetPlayerPos(playerid,1228.7247,-1565.4233,13.5741); }
		SendClientMessage(playerid,GRAY,"Teleported!");
		}
		return 1;
}
Reply
#2

Firstly, sscanf specifier s need the array size. If you are looking for an integer, you should use "i".
Secondly, you can't compare string like that. Use strcmp but I highly doubt that what you want. Remove the quotes of numbers, you don't need it.
Reply
#3

Strings are arrays of symbols, read some theory @ SA-MP wiki.

Код:
CMD:port(playerid,params[])
{
		new lokejsn[8]; //Since lokejsn is a string, you define it as an array like that.
		if(sscanf(params,"s[8]",lokejsn)) return SendClientMessage(playerid,COLOR_GREY,"Usage: /port [location]");
                //I have to admit, since you type location ID, if I were you, I had rather stick to integer, but it's up to you to decide that, so I'll patch it up your way.
                //You do need to define array size in sscanf line there; and you don't need to do !sscanf later, it's irrelative and is not required.
                if(!strcmp(lokejsn, "1", true)) { JBC_SetPlayerPos(playerid,1819.2871,-2066.6099,13.3828); }
                //DIY other location numbers like that
                ...
                ...
		if(!strcmp(lokejsn, "16", true)) { JBC_SetPlayerPos(playerid,1228.7247,-1565.4233,13.5741); }
		SendClientMessage(playerid,GRAY,"Teleported!");
		return 1;
}
Hope you get the idea. The variable you defined is an integer, not a string.

Код:
new lokejsn;
and you define strings as if you were defining an array...

Код:
new lokejsn[SIZE];
Reply
#4

Thank u two so much, especially Maxandmov.
+rep
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)