[Tutorial] Fixing Errors (most basic)
#1

Yo guys.
This is my first tutorial ever done, so please don't laugh if it is bad/useless/messy..

So I was going through the tutorials and realized that there are just a few threads that descrive how to fix errors. Since a am a rookie scripter, I will only tell you about the most frequent errors done by newbies. That's why this tutorial is specially for scripters who have started learning.
Let's start.
Код:
error 017: undefined symbol
This is a error message that tells you that you have just written a symbol/code name that is yet undefined.
Let's suppose we did following
pawn Код:
public OnPlayerConnect(playerid)
{
    SenClientMessage(playerid,0xFFFFFF,"You have connected to our server! Enjoy your stay!");
    return 1;
}
Oops! We just realized that we wrote "SenClientMessage" instead of "SendClientMessage", so this would give us the error saying that "SenClientMessage" is an undefined symbol. Things like these don't only occur by mistyping, they could also mean that you have forgotten to define a variable, or a colour name etc...
pawn Код:
public OnPlayerConnect(playerid)
{
    SendClientMessage(playerid,COL_BRIGHTBLUE,"You have connected to our server! Enjoy your stay!");
    return 1;
}
simply writing this would give us the error
Код:
error 017: undefined symbol "COL_BRIGHTBLUE
why? Because we forgot to define COL_BRIGHTBLUE above. So we'll have to define it.
pawn Код:
#define COL_BRIGHTBLUE 0xFFFFFF
Here's another common error:
Код:
: error 037: invalid string (possibly non-terminated string)
I don't know if a lot of people do this, but I do this so damn often...
Now looking at the error message, it says "possibly non-terminated string)", means that it could have been that the string wasn't completed. What could this mean? Simply that we didn't end the string. And example of this mistake:
pawn Код:
SendClientMessage(playerid,0xFFFFFF,"You have connected to our server! Enjoy your stay!);
non terminated string means, that we didn't tell the script that our message has ended. Now what does end a string in the function SendClientMessage? the ""s. Now we should've realized that we have forgotten to add a ' " ' to end the string. add it, and the error should be fixed.
Now that I think about it, this wrongly made code should give more errors, like "undefined symbol "You"", "undefined symbol "have"" etc, because the string hasn't ended, so the script will think that it is some sort of a function. But the compiler knows that the third argument of SendClientMessage is a string.
Concearning arguments:
Код:
error 035: argument type mismatch (argument [number])
Newbs might get this error often, since they sometimes forget the arguments of a function.
This error refers to a simple error. let's suppose we wrote this:
pawn Код:
SendClientMessage(0xFFFFFF,"You have connceted to our server! Enjoy your stay here!");
This would give us the error "argument type mismatch(argument 2)". This means that we haven't written the argument we should have written. This error says that there is something wrong with a certain argument, or doesn't make sense. Here are the parameters of SendClientMessage:
playerid, [colour], const message[]
Now, you should all have realized that we forgot the "playerid". Because we have to tell the script to WHOM we want to send the message.
Код:
warning 202: number of arguments does not match definition
This is also a mistake, that can be done, also concearns arguments. This says us that we haven't written the correct amount of arguments. Let's suppose we wrote something extremely stupid.... for god's sake, I'm just trying to explain, so don't laugh...
pawn Код:
SendClientMessage(playerid,0xFFFFFF,"You have connected to our server! Enjoy your stay!",playerid);
yea yea, who would write this...
Now looking at it, we wrote 4 arguments, even though the function SendClientMessage has 3 arguments. so we must remove the "playerid" at the very end, cause it's useless. a script doesn't need an extra explenation of what it needs to do. A human might forget whether he should give the cup of tea to his brother or his dad, but a script is rim by a computer, you know... but that doesn't mean it can't do mistakes... another common error:
Код:
error 001: expected token: ";", but found "[symbol]"
Errur numbah one!!!! So this error id numbah one tells you that a ";" is missing. example:
pawn Код:
SendClientMessage(playerid,0xFFFFFF,"You have connected to our server! Enjoy your stay!")
return 1;
This will gives us the error "expected token: ";" but found "return"" . EXTREMELY SIMPLY means that we forgot to write a ";" at the end of the function SendClientMessage(). now, when you look at the line given at the error, it will give you the error at the line of "return", because when he doesn't find that token behind SendClientMessage(), then he will look for it at the next line, and then the next, until he finds a symbol.



Well, a few last words...
This tutorial isn't completely finished, since I just realized that you have to explain a lot, so well.
Thanks a lot for reading, and I hope I helped you.

Updates
Here, you will find the updates and their post number. I won't edit the original topic, else it will get too long.


Update: April 21st 2014, post number 5
Update: April 30th 2014, post number 8
Reply
#2

a tutorial doesn't have to explain much. just enough detail so the reader could understand whatever it is you're trying to get across (something you haven't done)
Reply
#3

nice 1 good for newbies
Reply
#4

@ Ada,
I disagree. I personally don't like tutorials which simply say "add this and this, and finish, and then write a super short comment on what you have done."That is not my formula. I want to explain people what I am doing, otherwise a tutorial isn't a tutorial.Especially in these kinds of stuff like learning pawn for beginners, beginners need to know waht to do. When we hand them a code, then they will never understand. Thanks.
@superrobot
Thanks a lot.
Reply
#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
#6

Quote:
Originally Posted by NaClchemistryK
Посмотреть сообщение
I personally don't like tutorials which simply say "add this and this, and finish, and then write a super short comment on what you have done."
that's what a tutorial is! a bunch of do this and thats.. (you) the author must imply that the reader already understand whatever. (the language obviously) and just explain that (and the do's..)
Reply
#7

@Ada32, the more detailed a tutorial is the better.

This is a really good job for a new scripter. Hope you keep up the good work...
Reply
#8

This is a update to the topic. Updated on April 30th 2014.

Yo, sorry to make a late update, was very busy making my own server.

So last time we've talked about warnings. As you know, warnings should be fixed, but can also be left like that. But leaving it alone might cause it bugs.
So we are gonna go back to the main stuff we were supposed to do in this topic: fixing ERRORSSSSSSSSSSSSS
First I am gonna correct something I did wrong at my very first post.
Код:
error 001: expected token: ";", but found "[symbol]"
This error must not be given when you only forget the ";", but it can be for any token, though in some cases it will give some other errors because it can't say whether you really must have used that certain token or not. So it has to be like this:
Код:
error 001: expected token:"[symbol]", but found "[symbol]"
Don't always trust this error, it sometimes specifies you some tokens you wouldn't put there. So it is sometimes better to check stuff yourself. Example:
pawn Код:
public OnPlayerConnect(playerid)
{
    SendClientMessage(playerid,0xFFFFFF,"You have connected to our server! Enjoy your stay here!";
    return 1;
}
Now we should've realised that we forgot a bracket, but the compiler will give this error:
Код:
error 001: expected token: ",", but found ";"
it is saying us that he expected a comma to be there. Total bullshit, we just wanted to send him a message, and we forgot a bracket there. No need to trust the compiler in this situation.

So me having corrected that mistake, we can go on with the real stuff.
Alright, so when you do some useless shit and script something that doesn't make sense, you'll get this error:
Код:
fatal error 107: too many error messages on one line
well, this won't be the only error message shown. The compiler will show you some examples of mistakes you did on that line. Now there are trillions of examples, but I can't end it without an example.
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(IsPlayerAdmin = false)
    {
        Kick(playerid);
    }
    return 1;
}
alright, this might make a little sense for newbs, but doesn't for the compiler. You might want to check if a player is a rcon admin when he enters a vehicle. but the line expression " = false " makes NO sense.
when you want to use " = " you can only use it to give a certain variable a number.
pawn Код:
new innocentguy[MAX_PLAYERS];
new idioticDMer[MAX_PLAYERS];
public OnPlayerDeath(playerid,killerid)
{
        innocentguy[playerid] = playerid;
        idioticDMer[killerid] = killerid;
        return 1;
}
And we also tried to check whether the script IS setting the IsPlayerAdmin as false AT THE EXACT MOMENT, which makes even less sense.
If you had a little brain, you would rather use " == " to check whether it is set to false (which can't be), and also add a (playerid) behind IsPlayerAdmin if you have a little intelligence, and use
pawn Код:
if(!IsPlayerAdmin(playerid))
if you had scripting experience xD. The last one was correct, everything else was WRONGGG
Alright, so I cannot tell a lot about this error, since it can be any case where you did tons of mistakes, so let's go on.
Код:
error 076: syntax error in the expression, or invalid function call
alright, I created this error after experimenting the first thing I said there about adding the ==s, hehe
pawn Код:
if(IsPlayerAdmin == false)
This error is given when the logic isn't there, or we haven't "used" a function correctly. A quote from Wikipedia:
Quote:

The term syntax is also used to refer to the rules governing the behavior of mathematical systems, such as formal languages used in logic.
So let's look at the logic of this thing. the error says that we haven't expressed it correctly. Trying to check wether a Player is admin and at the same time checking whether it is SET to false doesn't make sense.
And we haven't used the correct functions. Lemme use another example of this error to explain the "function call" more clearly.
pawn Код:
public OnPlayerConnect(playerid)
{
    SetTimerEx("MoneyReward", 1200000,true,"i",playerid);//every 20 mins
    return 1;
}

forward MoneyReward(playerid);
public MoneyReward(playerid)
{
    GivePlayerMoney(playerid,300000);
    SendClientMessage(playerid,0xFFFFFFFF,"Thank you for playing for 20 minutes!");
}

public OnPlayerDisconnect(playerid, reason)
{
    KillTimer(MoneyReward);
    return 1;
}
This is a mistake I used to do.....
Alright, here we've set a timer, and every 20 mins it gave 300K to the player who played 20 mins. Then we tried to end that timer when he disconnected.
But we did something wrong. The first parameter of SetTimerEx is functionname[]. We just gave it our own name, but it is still a function. And we cannot kill a function. This is for example an incorrect "call" of a function. Or rather incorrect kill xDDD


So that's it again for this day, or rather week. I don't have much time to look for more errors, I have an own server ta script, sry!
So cya next time guys.
Reply
#9

This made my day. Are you dumb NaClchemistryK?
Reply
#10

Was just a joke bro, I knew there were already a few of those threads.
Quote:

Ah, dat little guy, gimme the credits at least for giving you the idea of making a thread that has something to do with fixing errors!! no fair bro

Now don't ruin mah rep just cuz I constructed a lil' joke here on da forumzz
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)