Need Help With this Unreachable Code
#1

Ok, So i'm trying to get it so this code is reachable

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new string[256];
    new plname[MAX_PLAYER_NAME];
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new veh = GetPlayerVehicleID(playerid);
        //if(Engine[veh] == 0)
        {
          //TogglePlayerControllable(playerid, 1);
          //SendClientMessage(playerid, COLOR_GREY, "The engine is off, use /engine or press SHIFT to start it.");
            //if(VehicleInfo[veh][vRentPrice] > 0)
            {
                GetPlayerName(playerid, plname, sizeof(plname));
                //if(strcmp(plname, VehicleInfo[veh][vOwner], true) == 0 || vRented[veh] == playerid)
                {
              //    format(string, sizeof(string), "--|Welcome to a %s|--", VehicleNames[GetVehicleModel(veh)-400]);
              //    SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
              //    return 1;
              }
            //  else
                {
                    //if(vRented[veh] != 255)
                {
                    //  TogglePlayerControllable(playerid, );
                //  format(string, sizeof(string), "~w~This %s if for rent ~n~Price: ~b~$%d ~n~~w~Owner: ~b~%s ~n~~w~use /rent vehicle to rent it.", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vRentPrice], VehicleInfo[veh][vOwner]);
                //  GameTextForPlayer(playerid, string, 12000, 5);
                //  return 1;
            }
            //else
            {
                        if(VehicleInfo[veh][vAlarm] > 0)
                        {
                            format(string, sizeof(string), "WARNING: This %s is for %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                        SendClientMessage(playerid, COLOR_LIGHTRED, string);
                        SendClientMessage(playerid, COLOR_LIGHTRED, "WARNING: the alarm is enabled.");
                            PlayAlarmSound(veh, VehicleInfo[veh][vAlarm]*10, VehicleInfo[veh][vAlarm]*10000);
                            return 1;
                        }
                        else
                        {
                            format(string, sizeof(string), "WARNING: This %s is for %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                        SendClientMessage(playerid, COLOR_LIGHTRED, string);
                        return 1;
                        }
                    }
                }
            }
            if(VehicleInfo[veh][vOwned] == 1)
        {
                GetPlayerName(playerid, plname, sizeof(plname));
            //  if(strcmp(plname, VehicleInfo[veh][vOwner], true) == 0 || vRented[veh] == playerid)
                {
                format(string, sizeof(string), "--|Welcome back to your %s|--", VehicleNames[GetVehicleModel(veh)-400]);
                SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                return 1;
                }
            //  else
                {
                if(VehicleInfo[veh][vAlarm] > 0)
                    {
                        format(string, sizeof(string), "Info: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    SendClientMessage(playerid, COLOR_LIGHTRED, "Info: The Alarm Is On.");
                        PlayAlarmSound(veh, VehicleInfo[veh][vAlarm]*10, VehicleInfo[veh][vAlarm]*10000);
                        return 1;
                    }
                    else
                    {
                        format(string, sizeof(string), "Info: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    return 1;
                }
                }
            }
        }
        //else
        {
            if(VehicleInfo[veh][vOwned] == 1)
        {
                GetPlayerName(playerid, plname, sizeof(plname));
                if(strcmp(plname, VehicleInfo[veh][vOwner], true) == 0)
                {
                format(string, sizeof(string), "WARNING: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                return 1;
                }
                else
                {
                    if(VehicleInfo[veh][vAlarm] > 0)
                    {
                        format(string, sizeof(string), "WARNING: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    SendClientMessage(playerid, COLOR_LIGHTRED, "WARNING: the alarm is enabled.");
                        PlayAlarmSound(veh, VehicleInfo[veh][vAlarm]*10, VehicleInfo[veh][vAlarm]*10000);
                        return 1;
                    }
                    else
                    {
                        format(string, sizeof(string), "WARNING: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    return 1;
                }
                }
            }
        }
    }
    return 1;
}
The errors i get
Код:
C:\Users\name\Desktop\sa-mp server\filterscripts\Vehicles_system.pwn(3088) : warning 225: unreachable code
C:\Users\name\Desktop\sa-mp server\filterscripts\Vehicles_system.pwn(3098) : warning 225: unreachable code
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase

Header size:      2236 bytes
Code size:      144608 bytes
Data size:     2759584 bytes
Stack/heap size:   16384 bytes; estimated max. usage=4211 cells (16844 bytes)
Total requirements: 2922812 bytes

2 Warnings.
I'm new to scirpting, I'm trying to learn here..How can i make it so this code is reachable after i have commented the stuff that is commented out.

Will you need the whole scirpt or will this do fine.


Edit:
Here is the whole scirpt that i have edited
http://pastebin.com/m68df6441
Reply
#2

What about removing those // ? Theyґre prolly causing them.
Reply
#3

Quote:
Originally Posted by Mo3
What about removing those // ? Theyґre prolly causing them.
They prolly are but i'm so new in scirpting thats the only way i know how to disable stuff besudes /* */ but when i do that Pawno crashes
Reply
#4

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new string[256];
    new plname[MAX_PLAYER_NAME];
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new veh = GetPlayerVehicleID(playerid);
        if(Engine[veh] == 0)
        {
          TogglePlayerControllable(playerid, 1);
          SendClientMessage(playerid, COLOR_GREY, "The engine is off, use /engine or press SHIFT to start it.");
            if(VehicleInfo[veh][vRentPrice] > 0)
            {
                GetPlayerName(playerid, plname, sizeof(plname));
                if(strcmp(plname, VehicleInfo[veh][vOwner], true) == 0 || vRented[veh] == playerid)
                {
                format(string, sizeof(string), "--|Welcome to a %s|--", VehicleNames[GetVehicleModel(veh)-400]);
                SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                return 1;
              }
              else
                {
                    if(vRented[veh] != 255)
                    {
                        TogglePlayerControllable(playerid, );
                    format(string, sizeof(string), "~w~This %s if for rent ~n~Price: ~b~$%d ~n~~w~Owner: ~b~%s ~n~~w~use /rent vehicle to rent it.", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vRentPrice], VehicleInfo[veh][vOwner]);
                    GameTextForPlayer(playerid, string, 12000, 5);
                    return 1;
                    }
            }
            else
            {
                    if(VehicleInfo[veh][vAlarm] > 0)
                    {
                        format(string, sizeof(string), "WARNING: This %s is for %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    SendClientMessage(playerid, COLOR_LIGHTRED, "WARNING: the alarm is enabled.");
                        PlayAlarmSound(veh, VehicleInfo[veh][vAlarm]*10, VehicleInfo[veh][vAlarm]*10000);
                        return 1;
                    }
                    else
                    {
                        format(string, sizeof(string), "WARNING: This %s is for %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    return 1;
                    }
              }
            }
           
            if(VehicleInfo[veh][vOwned] == 1)
        {
                GetPlayerName(playerid, plname, sizeof(plname));
                if(strcmp(plname, VehicleInfo[veh][vOwner], true) == 0 || vRented[veh] == playerid)
                {
                format(string, sizeof(string), "--|Welcome back to your %s|--", VehicleNames[GetVehicleModel(veh)-400]);
                SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                return 1;
                }
                else
                {
                    if(VehicleInfo[veh][vAlarm] > 0)
                    {
                        format(string, sizeof(string), "Info: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    SendClientMessage(playerid, COLOR_LIGHTRED, "Info: The Alarm Is On.");
                        PlayAlarmSound(veh, VehicleInfo[veh][vAlarm]*10, VehicleInfo[veh][vAlarm]*10000);
                        return 1;
                    }
                    else
                    {
                        format(string, sizeof(string), "Info: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    return 1;
                }
                }
            }
        }
        else
        {
            if(VehicleInfo[veh][vOwned] == 1)
        {
                GetPlayerName(playerid, plname, sizeof(plname));
                if(strcmp(plname, VehicleInfo[veh][vOwner], true) == 0)
                {
                format(string, sizeof(string), "WARNING: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                return 1;
                }
                else
                {
                    if(VehicleInfo[veh][vAlarm] > 0)
                    {
                        format(string, sizeof(string), "WARNING: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    SendClientMessage(playerid, COLOR_LIGHTRED, "WARNING: the alarm is enabled.");
                        PlayAlarmSound(veh, VehicleInfo[veh][vAlarm]*10, VehicleInfo[veh][vAlarm]*10000);
                        return 1;
                    }
                    else
                    {
                        format(string, sizeof(string), "WARNING: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    return 1;
                }
                }
            }
        }
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by Calon
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new string[256];
    new plname[MAX_PLAYER_NAME];
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new veh = GetPlayerVehicleID(playerid);
        if(Engine[veh] == 0)
        {
          TogglePlayerControllable(playerid, 1);
          SendClientMessage(playerid, COLOR_GREY, "The engine is off, use /engine or press SHIFT to start it.");
            if(VehicleInfo[veh][vRentPrice] > 0)
            {
                GetPlayerName(playerid, plname, sizeof(plname));
                if(strcmp(plname, VehicleInfo[veh][vOwner], true) == 0 || vRented[veh] == playerid)
                {
                format(string, sizeof(string), "--|Welcome to a %s|--", VehicleNames[GetVehicleModel(veh)-400]);
                SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                return 1;
              }
              else
                {
                    if(vRented[veh] != 255)
                    {
                        TogglePlayerControllable(playerid, );
                    format(string, sizeof(string), "~w~This %s if for rent ~n~Price: ~b~$%d ~n~~w~Owner: ~b~%s ~n~~w~use /rent vehicle to rent it.", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vRentPrice], VehicleInfo[veh][vOwner]);
                    GameTextForPlayer(playerid, string, 12000, 5);
                    return 1;
                    }
            }
            else
            {
                    if(VehicleInfo[veh][vAlarm] > 0)
                    {
                        format(string, sizeof(string), "WARNING: This %s is for %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    SendClientMessage(playerid, COLOR_LIGHTRED, "WARNING: the alarm is enabled.");
                        PlayAlarmSound(veh, VehicleInfo[veh][vAlarm]*10, VehicleInfo[veh][vAlarm]*10000);
                        return 1;
                    }
                    else
                    {
                        format(string, sizeof(string), "WARNING: This %s is for %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    return 1;
                    }
              }
            }
           
            if(VehicleInfo[veh][vOwned] == 1)
        {
                GetPlayerName(playerid, plname, sizeof(plname));
                if(strcmp(plname, VehicleInfo[veh][vOwner], true) == 0 || vRented[veh] == playerid)
                {
                format(string, sizeof(string), "--|Welcome back to your %s|--", VehicleNames[GetVehicleModel(veh)-400]);
                SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                return 1;
                }
                else
                {
                    if(VehicleInfo[veh][vAlarm] > 0)
                    {
                        format(string, sizeof(string), "Info: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    SendClientMessage(playerid, COLOR_LIGHTRED, "Info: The Alarm Is On.");
                        PlayAlarmSound(veh, VehicleInfo[veh][vAlarm]*10, VehicleInfo[veh][vAlarm]*10000);
                        return 1;
                    }
                    else
                    {
                        format(string, sizeof(string), "Info: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    return 1;
                }
                }
            }
        }
        else
        {
            if(VehicleInfo[veh][vOwned] == 1)
        {
                GetPlayerName(playerid, plname, sizeof(plname));
                if(strcmp(plname, VehicleInfo[veh][vOwner], true) == 0)
                {
                format(string, sizeof(string), "WARNING: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                return 1;
                }
                else
                {
                    if(VehicleInfo[veh][vAlarm] > 0)
                    {
                        format(string, sizeof(string), "WARNING: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    SendClientMessage(playerid, COLOR_LIGHTRED, "WARNING: the alarm is enabled.");
                        PlayAlarmSound(veh, VehicleInfo[veh][vAlarm]*10, VehicleInfo[veh][vAlarm]*10000);
                        return 1;
                    }
                    else
                    {
                        format(string, sizeof(string), "WARNING: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    return 1;
                }
                }
            }
        }
    }
    return 1;
}
all the stuff i have quoted out is stuff i've disabled in the scirpt. Is there a way to leave them quoted out and make that code reachable?
Reply
#6

Quote:
Originally Posted by ihatetn931
Quote:
Originally Posted by Calon
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    new string[256];
    new plname[MAX_PLAYER_NAME];
    if(newstate == PLAYER_STATE_DRIVER)
    {
        new veh = GetPlayerVehicleID(playerid);
        if(Engine[veh] == 0)
        {
          TogglePlayerControllable(playerid, 1);
          SendClientMessage(playerid, COLOR_GREY, "The engine is off, use /engine or press SHIFT to start it.");
            if(VehicleInfo[veh][vRentPrice] > 0)
            {
                GetPlayerName(playerid, plname, sizeof(plname));
                if(strcmp(plname, VehicleInfo[veh][vOwner], true) == 0 || vRented[veh] == playerid)
                {
                format(string, sizeof(string), "--|Welcome to a %s|--", VehicleNames[GetVehicleModel(veh)-400]);
                SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                return 1;
              }
              else
                {
                    if(vRented[veh] != 255)
                    {
                        TogglePlayerControllable(playerid, );
                    format(string, sizeof(string), "~w~This %s if for rent ~n~Price: ~b~$%d ~n~~w~Owner: ~b~%s ~n~~w~use /rent vehicle to rent it.", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vRentPrice], VehicleInfo[veh][vOwner]);
                    GameTextForPlayer(playerid, string, 12000, 5);
                    return 1;
                    }
            }
            else
            {
                    if(VehicleInfo[veh][vAlarm] > 0)
                    {
                        format(string, sizeof(string), "WARNING: This %s is for %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    SendClientMessage(playerid, COLOR_LIGHTRED, "WARNING: the alarm is enabled.");
                        PlayAlarmSound(veh, VehicleInfo[veh][vAlarm]*10, VehicleInfo[veh][vAlarm]*10000);
                        return 1;
                    }
                    else
                    {
                        format(string, sizeof(string), "WARNING: This %s is for %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    return 1;
                    }
              }
            }
           
            if(VehicleInfo[veh][vOwned] == 1)
        {
                GetPlayerName(playerid, plname, sizeof(plname));
                if(strcmp(plname, VehicleInfo[veh][vOwner], true) == 0 || vRented[veh] == playerid)
                {
                format(string, sizeof(string), "--|Welcome back to your %s|--", VehicleNames[GetVehicleModel(veh)-400]);
                SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                return 1;
                }
                else
                {
                    if(VehicleInfo[veh][vAlarm] > 0)
                    {
                        format(string, sizeof(string), "Info: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    SendClientMessage(playerid, COLOR_LIGHTRED, "Info: The Alarm Is On.");
                        PlayAlarmSound(veh, VehicleInfo[veh][vAlarm]*10, VehicleInfo[veh][vAlarm]*10000);
                        return 1;
                    }
                    else
                    {
                        format(string, sizeof(string), "Info: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    return 1;
                }
                }
            }
        }
        else
        {
            if(VehicleInfo[veh][vOwned] == 1)
        {
                GetPlayerName(playerid, plname, sizeof(plname));
                if(strcmp(plname, VehicleInfo[veh][vOwner], true) == 0)
                {
                format(string, sizeof(string), "WARNING: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
                return 1;
                }
                else
                {
                    if(VehicleInfo[veh][vAlarm] > 0)
                    {
                        format(string, sizeof(string), "WARNING: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    SendClientMessage(playerid, COLOR_LIGHTRED, "WARNING: the alarm is enabled.");
                        PlayAlarmSound(veh, VehicleInfo[veh][vAlarm]*10, VehicleInfo[veh][vAlarm]*10000);
                        return 1;
                    }
                    else
                    {
                        format(string, sizeof(string), "WARNING: This %s belongs to %s", VehicleNames[GetVehicleModel(veh)-400], VehicleInfo[veh][vOwner]);
                    SendClientMessage(playerid, COLOR_LIGHTRED, string);
                    return 1;
                }
                }
            }
        }
    }
    return 1;
}
all the stuff i have quoted out is stuff i've disabled in the scirpt. Is there a way to leave them quoted out and make that code reachable?
Use your brain, I've corrected most of your code. I'm pretty sure it's fine.
Reply
#7

the reason it didnt work is you close the beginning of the if statement then tried to make it work from the middle of the if statement.

you cant start an if statement from an else

ie

if(){
if(){
if(){
}
}
}

each if has to be opened and closed

if i was to take away one of those ifs without sorting the other end of it, it will throw up an exception

example

if(){
//if(){
if(){
}
}
}

there are still 3 closes but only 2 opens

which means that the script is trying to close something that isnt there (or maybe the entire function) before its sposed to.

note that all public functions work the same way:

public OnPlayerStateChange(playerid, newstate, oldstate)
{
}

so you might be removing something in the middle but accidentally ending the public function too early and leaving script that isnt related to anything outside a function.

this is what throws up exceptions. as you are new to coding having an explanation is handy.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)