[Tutorial] Fixing Errors (most basic)
#5

This is a update to the topic. Updated on April 21st 2014.

So, now we already have looked at several errors. Now sometimes when you compile a script, you will sometimes find warnings. Lemme tell you the difference between warnings and errors.
When you compile a scriptand get errors, that means that you cannot run this script. When you write a script and run it, the server won't ignore any part of the script. And if we would be able to run a script with an error, the server would crash. Why? because there is something in the script that cannot be run. In a warning, the compiler will say you that there is something wrong, but a warning is sort of a "smaller" error, so this (probably) wouldn't crash the server. But the fact that the script will run perfectly without bugs isn't guaranteed when you get a warning.

One warning has already been introduced to you, so let's look at some others.... /me tries to script warnings
Код:
warning 209: function "OnPlayerCommandText" should return a value
/me succeeds
Okay, so this warning tells us that we didn't return a value to the function OnPlayerCommandText. We did this:
pawn Код:
public OnPlayerCommandText(playerid,cmdtext[])
{
    if(strcmp("/commands", cmdtext, true, 9) == 0)
    {
        SendClientMessage(playerid,0xFFFFFF,"Commands: /kill, /teleports, /animation");
        return 1;
    }
return;
}
Until now we have only been playing around with SendClientMessage...
Whatever... This little mistake usually doesn't happen, but lemme explain. Usually, the function OnPlayerCommandText() returns the value 0. When the value 0 is returned, the clientmessage "SERVER: Unknow Command" will be shown. when the value 1 is returned, that message won't be sent. The value 1 is returned in the line after the function SendClientMessage(). But what if a player wrote /commanddds by accident instead of /commands? what would happen is that that message won't be shown. This script could be used, but there will be something wrong.

Now a warning that sometimes is shown:
Код:
warning 217: loose indentation
Now, "indentation" is another word for entry. Let's suppose we did this:
pawn Код:
if(strcmp("/commands", cmdtext, true, 9) == 0)
{
SendClientMessage(playerid,0xFFFFFF,"Commands: /kill, /teleports, /animation");
         return 1;
}
Looking at it, we can see that we didn't make the entries as the script would like to see it. When a brace is opened (a {), we have to allign all the functions at the same column. So we have to move our mouse behind SendClientMessage(), click the left mouse button and hit TABBBBBBBBBBBBBBBBBBB!!!!!!!!! Or we could move the "return 1;" back at the same column as SendClientMessage
I don't know if this script would run correctly, since I always correct this mistake... so whatever.

Код:
warning 203: symbol is never used: "[variable name]"
This warning tells us that we created a variable, but we haven't used it yet. Don't bother paying attention to this warning, since it won't harm your server.
There is also another similar warning to the one above:
Код:
warning 204: symbol is assigned a value that is never used: "[variable name]"
This tells us that we actually made a variable, and gave it a value. But we never used it. Let's suppose we did this
pawn Код:
new innocentguy;

public OnPlayerDeath(playerid, killerid, reason)
{
    innocentguy = playerid;
    return 1;
}
This will set the value of the variable innocentguy to the id of the player. But we've never used it, that's why it will warn us. But also don't bother paying attention to this. warnings like these won't harm your script.

So this is all for today. Sorry for such a short one this time, I am very busy nowadays.
To be continued
Reply


Messages In This Thread
Fixing Errors (most basic) - by NaClchemistryK - 15.04.2014, 09:27
Re: Fixing Errors (most basic) - by Ada32 - 15.04.2014, 10:12
Re: Fixing Errors (most basic) - by superrobot48 - 15.04.2014, 11:46
Re: Fixing Errors (most basic) - by NaClchemistryK - 15.04.2014, 14:47
Re: Fixing Errors (most basic) - by NaClchemistryK - 21.04.2014, 17:44
Re: Fixing Errors (most basic) - by Ada32 - 21.04.2014, 18:08
Re: Fixing Errors (most basic) - by Abagail - 21.04.2014, 22:36
Re: Fixing Errors (most basic) - by NaClchemistryK - 30.04.2014, 16:11
Re: Fixing Errors (most basic) - by iZN - 30.04.2014, 16:40
Re: Fixing Errors (most basic) - by NaClchemistryK - 01.05.2014, 08:21

Forum Jump:


Users browsing this thread: 1 Guest(s)