error 033: array must be indexed (variable "-unknown-")
#1

I'm getting the following error message on each if(tgate line:

error 033: array must be indexed (variable "-unknown-")


The command and what I'm trying to do is pretty self explanatory. This is the first time I haven't been able to debug something by myself so any help is greatly appreciated. I've tried using format() too with no luck.

Код:
CMD:agate(playerid, params[]) {

	new tgate;

	if(PlayerIsL3A(playerid) == 1) {
	
	    if(sscanf(params, "s[1]", tgate)) return SendClientMessage(playerid, -1, "USAGE: /agate [gate]");
	    
			if(tgate == "a") {
			
			    if(GateO[0] == false) {
			    
			        MoveObject(Gate[0], 120.81, 1942.33, 21.63, 2.00);
			        GateO[0] = true;
			        
				} else if (GateO[0] == true) {

				    MoveObject(Gate[0], 134.67, 1942.33, 21.63, 2.00);
				    GateO[0] = false;
				    
	            }
	            
			} else if (tgate == "b") {
			
			    if(GateO[1] == false) {

			        MoveObject(Gate[1], 96.93, 1925.09, 18.22, 2.00);
			        GateO[1] = true;

				} else if (GateO[1] == true) {

				    MoveObject(Gate[1], 96.93, 1922.42, 18.22, 2.00);
				    GateO[1] = false;

	            }
	            
			} else if (tgate == "c") {
			
			    if(GateO[2] == false) {

			        MoveObject(Gate[2], 286.00, 1834.60, 19.99, 2.00);
			        GateO[2] = true;

				} else if (GateO[2] == true) {

				    MoveObject(Gate[2], 286.00, 1821.38, 19.99, 2.00);
				    GateO[2] = false;

	            }

			} else {
			
			    SendClientMessage(playerid, COLOR_YELLOW, "[ ! ] The gate ID you provided was invalid.");
			    
			}
			
	}
	
	return 1;
	
}
Reply
#2

You can't compare strings in PAWN with ==. Use strcmp(), it returns 0 if both strings are the same:

pawn Код:
//Returns 0, success:
strcmp("something", "something");
Also, tgate isn't a fixed-length array, so it won't be treated as a string:

pawn Код:
//Treated as a integer/char:
new tgate;

//Treated as an integer/char array,  we can store strings in there:
new tgate[32];

pawn Код:
CMD:agate(playerid, params[]) {

    new tgate[32];

    if(PlayerIsL3A(playerid) == 1) {
   
        if(sscanf(params, "s[32]", tgate)) return SendClientMessage(playerid, -1, "USAGE: /agate [gate]");
       
            if( !strcmp(tgate, "a") ) {
           
                if(GateO[0] == false) {
               
                    MoveObject(Gate[0], 120.81, 1942.33, 21.63, 2.00);
                    GateO[0] = true;
                   
                } else if (GateO[0] == true) {

                    MoveObject(Gate[0], 134.67, 1942.33, 21.63, 2.00);
                    GateO[0] = false;
                   
                }
               
            } else if ( !strcmp(tgate, "b") ) {
           
                if(GateO[1] == false) {

                    MoveObject(Gate[1], 96.93, 1925.09, 18.22, 2.00);
                    GateO[1] = true;

                } else if (GateO[1] == true) {

                    MoveObject(Gate[1], 96.93, 1922.42, 18.22, 2.00);
                    GateO[1] = false;

                }
               
            } else if ( !strcmp(tgate, "c") ) {
           
                if(GateO[2] == false) {

                    MoveObject(Gate[2], 286.00, 1834.60, 19.99, 2.00);
                    GateO[2] = true;

                } else if (GateO[2] == true) {

                    MoveObject(Gate[2], 286.00, 1821.38, 19.99, 2.00);
                    GateO[2] = false;

                }

            } else {
           
                SendClientMessage(playerid, COLOR_YELLOW, "[ ! ] The gate ID you provided was invalid.");
               
            }
           
    }
   
    return 1;
   
}
Should work, untested.
Reply
#3

if you only intend to use a single letter to name the gates, you could use sscanf's c (character) specifier.
pawn Код:
new tgate; // not an array

if(sscanf(params, "c", tgate)) ...

switch(tgate)
{
    case 'a', 'A': {} // Note: single quotes!
    case 'b', 'B': {}
    case 'c', 'C': {}
}
Reply
#4

Ah, okay. Thanks guys! Appreciate the help... I've haven't run into string comparison in pawn yet and I'm used to PHP.

Thanks again!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)