Help with Clean GM (some questions/problems) please help!
#6

The loose indentation:
This means the code is a bit messy. That doesn't matter, as an beginner.
A tip, to make a clean code:

Код:
After using an bracket (open bracket) or an if statement, use on the new line a TAB. Example:
pawn Код:
if(this){ //And after this an TAB [= 4 spaces]    print("this is true!"); }//close bracket. Same line as the bracket opener
or, a better code:
pawn Код:
if(this)    print("this is true!");
You had, for example:

pawn Код:
public EngineTimer(playerid)
{
    new rand = random(2);

        if(rand == 0)
        {
    SendClientMessage(playerid, COLOR_GREEN, "Engine Started...");
        SendClientMessage(playerid, COLOR_YELLOW, "To turn off the vehicle, Type (/engine)");
        new vehicleid = GetPlayerVehicleID(playerid);
        Engine[vehicleid] = 1;
        TogglePlayerControllable(playerid, 1);
        }

        if(rand == 1)
        {
    SendClientMessage(playerid, COLOR_GREEN, "Engine Failed...");
    SendClientMessage(playerid, COLOR_YELLOW, "Try Again");
        }

}
And now the "clean" version

pawn Код:
public EngineTimer(playerid)
{
    new rand = random(2);

    if(rand == 0)
    {
        SendClientMessage(playerid, COLOR_GREEN, "Engine Started...");
        SendClientMessage(playerid, COLOR_YELLOW, "To turn off the vehicle, Type (/engine)");
        new vehicleid = GetPlayerVehicleID(playerid);
        Engine[vehicleid] = 1;
        TogglePlayerControllable(playerid, 1);
    }
    else if(rand == 1) //else if instead of 'if'
    {
        SendClientMessage(playerid, COLOR_GREEN, "Engine Failed...");
        SendClientMessage(playerid, COLOR_YELLOW, "Try Again");
    }
}
You see the difference? With an "clean" code, you can find error's faster. It also looks more pro and it is a better overview if you look for something.

- Kevin

p.s.
I've editted my previous post. Read the 'p.s.'
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)