Welcome to 0.2 compiler features
Some of you may have problems converting their scripts to 0.2. We have this compiler to validate your source code, so Y_Less added new features to it, to make your source even more valid.
In that short HowTo I'll focus on how to fix those warnings and errors, which appear for most of you, when trying to compile an 0.1b script with the new 0.2 compiler.
Example
Following code is wrong formated:
PAWN Code:
public PlayerName(playerid) { // wrong 'public'. Because publics can't return arrays/strings, and PlayerName is not called by SetTimer. Use stock here.
new name[255]; // missing indention, at least 4 spaces or one tab.
if (IsPlayerConnected(playerid)) { // missing indention, at least 4 spaces or one tab.
GetPlayerName(playerid, name, MAX_STRING); // missing indention, at least 8 spaces or two tabs.
} // missing indention, at least 4 spaces or one tab.
else name[0]=0; // missing indention or should be appended to the previous line
return name; // missing indention, at least 4 spaces or one tab.
}
Following code will give no warnings and is correct formated:
PAWN Code:
stock PlayerName(playerid) {
new name[255];
if (IsPlayerConnected(playerid)) {
GetPlayerName(playerid, name, MAX_STRING);
} else name[0]=0;
return name;
}
Details
warning 217: loose indentation
Following error appears if you have formated your source like in the bad example at the beginning. Make it like the correct formated example at the beginning. If you have problems with special lines, ask here!
warning 235: public function lacks forward declaration
In 0.2 the compiler figures out (and actively uses) the difference of public and stock keywords.
Explanation on the keywords:
- stock (pawn-lang.pdf: ... any stock function that is not referred to, is completely skipped ...)
- public Functions which will be called by a timer, and not referenced directly. They always need to have a forward
HowTo make a forward:
To create a forward declaration, precede the function name and its parameter list with the keyword forward.
PAWN Code:
forward OnTimer1();
All Callbacks, which SA-MP server does (for example OnPlayerText) have to be also public, because its delecrated forward in a_samp.inc.
HowTo convert now?
0. Check if your gamemode compiles under 0.1b. If not, fix it!
1. Basicly you should make all your functions stock.
2.1 After that, you search for SetTimer in your source and all functions, which are called there have to be linked public.
2.2. Because of the public you have to put for each timer function (e.g OnTimer1()) following at the beginning of your source:
PAWN Code:
forward OnTimer1();
3. Try to compile. Ignore warnings.
3.1 If you see errors poping up, you still have something made wrong while reformating. Fix that first.
3.2 If that works, proceed with step 4.
4. Check the warnings, fix all except the warning 217: loose indentation ones.
5.
Now lets finish that 217-warning. In that warning its all about, incorrect indentation of your source code.
See the examples of the beginning and try to make your fency code from the bad formated one to a correct formated one. And you are done! Often you need to indent lots of lines at once, in most editors you can use SHIFT+TAB or just TAB while having marked that code.
Thats it!
Have fun coding,
Jan (DracoBlue)
Further information:
- coding information 0.2
- New compiler / Note about Warnings