Switch() doesn't work at all
#1

title
PHP код:
COMMAND:ahouse(playerid,params[])
{
    if(!
Player[playerid][Authed] || Player[playerid][Admin] < 4) return SendClientError(playerid"You are not authorised to use this command.");
    new 
Params[3][20], Params3[120], query[400],string[200],zone[100]; 
    if(
sscanf(params"s[120]"string)) return SendClientUsage(playerid"/ahouse [ Create / Interior ]"); 
    
sscanf(string"s[20]s[20]s[120]"Params[0], Params[1],Params3); 
    if(!
strcmp(Params[0], "create"true))
    {
        new 
Float:px,Float:py,Float:pz;
        
GetPlayerPos(playerid,px,py,pz);
        
GetZone(px,py,pz,zone);
        
format(query,sizeof(query),"INSERT INTO houses (hOwner,hLocation,hX,hY,hZ) VALUES ('%s','%s','%f','%f','%f')",Name(playerid),zone,px,py,pz);
        
mysql_tquery(connection,query,"CreateHouse","i",playerid);
    }
    if(!
strcmp(Params[0], "interior"true))
    {
    new 
houseid strval(Params[1]); 
    new 
intid strval(Params3); 
    if(!
houseid) return SendClientUsage(playerid"/ahouse [HouseID] [InteriorID]"); 
    if(!
intid) return SendClientUsage(playerid"/ahouse [HouseID] [InteriorID]"); 
    new 
query3[200];
    switch(
intid)
        {
            case 
1:
            {
                
House[houseid][hIntX] = 140.17;
                
House[houseid][hIntY] = 1366.07;
                
House[houseid][hIntZ] = 1083.65;
                
House[houseid][hInterior] = 5;
                
format(query3,sizeof(query3),"UPDATE houses SET hIntX='%i'AND hIntY='%i' AND hIntZ='%i' AND hInterior'%i' WHERE id ='%i'",House[houseid][hIntX],House[houseid][hIntY],House[houseid][hIntZ],House[houseid][hInterior],houseid);
                
mysql_tquery(connection,query3,"");
            }
                case 
2:
                {
                
House[houseid][hIntX] = 2324.53;
                
House[houseid][hIntY] = -1149.54;
                
House[houseid][hIntZ] = 1050.71;
                
House[houseid][hInterior] = 12;
                
format(query3,sizeof(query3),"UPDATE houses SET hIntX='%i'AND hIntY='%i' AND hIntZ='%i' AND hInterior'%i' WHERE id ='%i'",House[houseid][hIntX],House[houseid][hIntY],House[houseid][hIntZ],House[houseid][hInterior],houseid);
                
mysql_tquery(connection,query3,"");
                }
                default:
                {
                    
SendStaffMessage(playerid,"This interior ID is not in use yet.");
                    return 
1;
                }
        }
    }
    
SendStaffMessage(playerid,"This houses interior has been updated.");
    return 
1;

So the "interior part" doesn't work.
The thing inside the switch don't get called at all.
Even if it's not 1,2 (so default), even default doesn't get called
Reply
#2

Try creating "debug" with prints in switch and out to see where code get "stopped".
Reply
#3

Quote:
Originally Posted by IFilip
Посмотреть сообщение
Try creating "debug" with prints in switch and out to see where code get "stopped".
restarted the server, works now, wtf
Reply
#4

Please use proper variable names. The name should convey the variable's purpose and should not be something generic like string or params.
Reply
#5

you need to 'break' every case
Reply
#6

Quote:
Originally Posted by CoaPsyFactor
Посмотреть сообщение
you need to 'break' every case
No? Switch isn't a loop.

pawn Код:
COMMAND:ahouse(playerid,params[])
{
    if (!Player[playerid][Authed] || Player[playerid][Admin] < 4)
        return SendClientError(playerid, "You are not authorised to use this command.");

    if (isnull(params))
            return SendClientUsage(playerid, "/ahouse [ Create / Interior ]");

    if (!strcmp(params, "create", true, 6))
    {
        if (params[6] != ' ' && params[6] != '\0')
            return SendClientUsage(playerid, "/ahouse [ Create / Interior ]");

        new Float: px, Float: py, Float: pz, zone[240];
        GetPlayerPos(playerid, px, py, pz);
        GetZone(px, py, pz, zone);
        format(zone, sizeof(zone), "INSERT INTO houses (hOwner,hLocation,hX,hY,hZ) VALUES ('%s','%s','%f','%f','%f')", Name(playerid), zone, px, py, pz);
        mysql_tquery(connection, zone, "CreateHouse", "i", playerid);
    }
    else if (!strcmp(params, "interior", true, 8))
    {
        if (params[8] != ' ' && params[8] != '\0')
            return SendClientUsage(playerid, "/ahouse interior [HouseID] [InteriorID]");

        new houseid, intid;
        if (sscanf(params[8], "dd", houseid, intid))
            return return SendClientUsage(playerid, "/ahouse interior [HouseID] [InteriorID]");

        new query[147];
        switch (intid)
        {
            case 1:
            {
                House[houseid][hIntX] = 140.17;
                House[houseid][hIntY] = 1366.07;
                House[houseid][hIntZ] = 1083.65;
                House[houseid][hInterior] = 5;
                format(query, sizeof(query),"UPDATE houses SET hIntX='%f'AND hIntY='%f' AND hIntZ='%f' AND hInterior='%i' WHERE id ='%i'",House[houseid][hIntX],House[houseid][hIntY],House[houseid][hIntZ],House[houseid][hInterior],houseid);
                mysql_tquery(connection,query,"");
            }
            case 2:
            {
                House[houseid][hIntX] = 2324.53;
                House[houseid][hIntY] = -1149.54;
                House[houseid][hIntZ] = 1050.71;
                House[houseid][hInterior] = 12;
                format(query,sizeof(query),"UPDATE houses SET hIntX='%f'AND hIntY='%f' AND hIntZ='%f' AND hInterior'%i' WHERE id ='%i'",House[houseid][hIntX],House[houseid][hIntY],House[houseid][hIntZ],House[houseid][hInterior],houseid);
                mysql_tquery(connection,query,"");
            }
            default:
            {
                SendStaffMessage(playerid,"This interior ID is not in use yet.");
                return 1;
            }
        }
        SendStaffMessage(playerid,"This houses interior has been updated.");
    }
    return 1;
}
I had nothing to do so I re-scripted your command.
Start organizing and start saving memory.

I also fixed your queries. You were using %i for floats, and there's a place where you were updating without using a =
Reply
#7

Quote:
Originally Posted by Stinged
Посмотреть сообщение
No? Switch isn't a loop.

pawn Код:
COMMAND:ahouse(playerid,params[])
{
    if (!Player[playerid][Authed] || Player[playerid][Admin] < 4)
        return SendClientError(playerid, "You are not authorised to use this command.");

    if (isnull(params))
            return SendClientUsage(playerid, "/ahouse [ Create / Interior ]");

    if (!strcmp(params, "create", true, 6))
    {
        if (params[6] != ' ' && params[6] != '\0')
            return SendClientUsage(playerid, "/ahouse [ Create / Interior ]");

        new Float: px, Float: py, Float: pz, zone[240];
        GetPlayerPos(playerid, px, py, pz);
        GetZone(px, py, pz, zone);
        format(zone, sizeof(zone), "INSERT INTO houses (hOwner,hLocation,hX,hY,hZ) VALUES ('%s','%s','%f','%f','%f')", Name(playerid), zone, px, py, pz);
        mysql_tquery(connection, zone, "CreateHouse", "i", playerid);
    }
    else if (!strcmp(params, "interior", true, 8))
    {
        if (params[8] != ' ' && params[8] != '\0')
            return SendClientUsage(playerid, "/ahouse interior [HouseID] [InteriorID]");

        new houseid, intid;
        if (sscanf(params[8], "dd", houseid, intid))
            return return SendClientUsage(playerid, "/ahouse interior [HouseID] [InteriorID]");

        new query[147];
        switch (intid)
        {
            case 1:
            {
                House[houseid][hIntX] = 140.17;
                House[houseid][hIntY] = 1366.07;
                House[houseid][hIntZ] = 1083.65;
                House[houseid][hInterior] = 5;
                format(query, sizeof(query),"UPDATE houses SET hIntX='%f'AND hIntY='%f' AND hIntZ='%f' AND hInterior='%i' WHERE id ='%i'",House[houseid][hIntX],House[houseid][hIntY],House[houseid][hIntZ],House[houseid][hInterior],houseid);
                mysql_tquery(connection,query,"");
            }
            case 2:
            {
                House[houseid][hIntX] = 2324.53;
                House[houseid][hIntY] = -1149.54;
                House[houseid][hIntZ] = 1050.71;
                House[houseid][hInterior] = 12;
                format(query,sizeof(query),"UPDATE houses SET hIntX='%f'AND hIntY='%f' AND hIntZ='%f' AND hInterior'%i' WHERE id ='%i'",House[houseid][hIntX],House[houseid][hIntY],House[houseid][hIntZ],House[houseid][hInterior],houseid);
                mysql_tquery(connection,query,"");
            }
            default:
            {
                SendStaffMessage(playerid,"This interior ID is not in use yet.");
                return 1;
            }
        }
        SendStaffMessage(playerid,"This houses interior has been updated.");
    }
    return 1;
}
I had nothing to do so I re-scripted your command.
Start organizing and start saving memory.

I also fixed your queries. You were using %i for floats, and there's a place where you were updating without using a =
of course you have to break or return each case, as it will fall through to next....

if u know how paste this code in browsers js console and see what happens

Код:
var test = function () {
	var a = 1, b = 'Nothing';

	switch (a) {
		case 1:
			b = 'One';
		case 2:
			b = 'Two';
		default:
			b = 'Unknown';
	}

	return b;
}

test();
Reply
#8

Quote:
Originally Posted by CoaPsyFactor
Посмотреть сообщение
-
PAWN isn't Javascript.
Reply
#9

Quote:
Originally Posted by CoaPsyFactor
Посмотреть сообщение
of course you have to break or return each case, as it will fall through to next....

if u know how paste this code in browsers js console and see what happens

Код:
var test = function () {
	var a = 1, b = 'Nothing';

	switch (a) {
		case 1:
			b = 'One';
		case 2:
			b = 'Two';
		default:
			b = 'Unknown';
	}

	return b;
}

test();
Go and try this in PAWN:

pawn Код:
new a = 1, b[8] = "Nothing";
switch (a)
{
    case 1:
        b = "One";
    case 2:
        b = "Two";
    default:
        b = "Unknown";
}
print(b);
Reply
#10

Quote:
Originally Posted by CoaPsyFactor
Посмотреть сообщение
of course you have to break or return each case, as it will fall through to next....

if u know how paste this code in browsers js console and see what happens

Код:
var test = function () {
	var a = 1, b = 'Nothing';

	switch (a) {
		case 1:
			b = 'One';
		case 2:
			b = 'Two';
		default:
			b = 'Unknown';
	}

	return b;
}

test();
in c++ its right not in pawn.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)