Undefined symbol

From SA-MP Wiki

Jump to: navigation, search

Undefined symbol is a Pawn compiler error message. The Pawn Language Guide formally defines this error as error 017, and explains that the error means "The symbol (variable, constant or function) is not declared".

The error will look roughly look like this: error 017: undefined symbol "WelcomePlayer"

Cause

The error occurs when a piece of code references a variable, constant or function that the compiler cannot find. Often, this error is encountered by scripters who recklessly copy and paste code from one script to another, not realizing that the code in question depends on other code in the original script. Another, more common mistake made by even the most experienced scripters, is misspelling symbols.

Example with a function

This is example where a function that does not exists is referenced. A reckless copy-paster is copying a piece for code from the original script (awesomeroleplay.pwn) to his or her own (supercoolrp.pwn). awesomeroleplay.pwn compiles without any warnings or errors.

The reckless copy-paster decides to copy this piece of code from the original script:

awesomeroleplay.pwn

public OnPlayerConnect(playerid)
{
    WelcomePlayer(playerid);
}

The reckless copy-paster replaces supercoolrp.pwn's OnPlayerConnect callback with the one from awesomeroleplay.pwn and then attemps to compile it. The compiler will, however, throw an error: error 017: undefined symbol "WelcomePlayer". This is because the function WelcomePlayer does not exist the paster's own script. In other words: the piece of code that the reckless copy-paster pasted, depends on other code in awesomeroleplay.pwn. The paster will need to copy the dependent script as well.

In the original script, the function WelcomePlayer is defined.

awesomeroleplay.pwn

WelcomePlayer(playerid)
{
    SendClientMessage(playerid, "Welcome to Interactive Roleplay!", 0xFF0000AA);
}

The reckless copy-paster will need to copy and paste this function into his own script as well to make the code compile correctly. If this function would also depend on other code, the paster will need to copy and paste that code as well. In fact, the paster would need to repeat this step until all dependencies are resolved.

Tips for resolving this error

  • Use Ctrl + F to find the missing symbol (note that the compiler will tell you what symbol is missing after the words undefined symbol!) in the original script. If the symbol is a variable, you will have to copy all code that is relevant to its "ecosystem", that is to say, all code that modifies the variable. For beginning scripters and reckless copy-pasters, this may be hard, because it requires a deep understanding of the code and code paths.
  • Look into the includes of the original script.
  • Make sure you are adding the right includes.
  • Make sure you are not misspelling the symbol.
Personal tools
Navigation
Toolbox