Lua Error Explanation

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
(Marked as Lua Reference. Removed Fix Difficulty (wtf?). Formatted nicely)
Line 1: Line 1:
 
 
== Attempt to call a nil value ==
 
== Attempt to call a nil value ==
  
Fix difficulty: Easy
+
'''Description:''' You tried to call a function that doesn't exist.
  
Description: You tried to call a function that doesn't exist.
+
'''Possible causes:'''
 +
* Your function might be defined in another lua state. (e.g Calling a function on the client that only exists on the * server.)
 +
* You're using a metafunction on the wrong kind of object. (e.g. Calling :SteamID() on a Vector)
 +
* The function you're calling has an error in it which means it is not defined.
 +
* You've misspelled the name of the function.
  
Possible causes:  
+
'''Ways to fix:'''
Your function might be defined in another lua state. (IE. Calling a serverside function on the client.)
+
* Make sure the function exists
You're using a function on the wrong kind of object. (IE. Trying to call SetTarget() on a player.)
+
* Make sure your function is defined in the correct realm
The function you're calling has an error in it which means it is not defined.
+
* Check your function calls for spelling errors
You've simply mispelt the name of the function.
+
  
Ways to fix: Check your function calls for spelling errors. E.g. Entity.Kil will throw this error, use Entity.Kill and it'll be fixed right away!
 
  
 +
== Attempt to perform arithmetic on global '?' (a nil value) ==
  
== Attempt to perform arithmetic on field '?' (a nil value) ==
+
'''Description:''' You tried to perform arithmetic (+, -, *, /) on a global variable that is not defined.
  
Fix difficulty: Medium
+
'''Possible causes:'''
 +
* You tried to use a local variable that was defined later in the code
 +
* You've misspelled the name of the global variable
  
Description: You tried to perform arithmetic (+, -, *, /) on a variable that's nil. (isn't defined yet)
+
'''Ways to fix:'''
 +
* Make sure you define local variables before calling them in the code
 +
* Check for spelling errors
  
Ways to fix: Make sure before you use variables you check if they're nil. Using variables which equal nil can lead to lots of errors.
+
== Attempt to perform arithmetic on '?' (a type value) ==
 +
 
 +
'''Description:''' You tried to perform arithmetic (+, -, *, /) on a variable that cannot perform arithmetic. (e.g. 2 + "some string")
  
  
 
== Attempt to index global 'varname' (a nil value) ==
 
== Attempt to index global 'varname' (a nil value) ==
  
Fix difficulty: Easy
+
'''Description:''' You tried to index an undefined variable (e.g. ''print( variable.index )'' where ''variable'' is undefined)
 
+
Description: You tried to assign an index on an array that's nil. (isn't defined yet)
+
 
+
Possible causes:
+
The array might be defined somewhere else, or in another lua state.
+
Spelling errors.
+
 
+
Ways to fix: Make sure before you use arrays you check if they're nil.
+
 
+
  
== Malformed number near 'numb' ==
+
'''Possible causes:'''
 +
* The variable is defined in a different realm
 +
* The variable is local and defined later in the code
 +
* You've misspelled the name of the variable
  
Fix difficulty: Easy
+
'''Ways to fix:'''
 +
* Make sure the variable is only accessed in the realm it was defined in
 +
* If the variable is local, define it before accessing it
  
Description: You messed up a number, somehow.
+
== Malformed number near 'number' ==
  
Possible causes:  
+
'''Description:''' There is a malformed number in the code (e.g. 1.2.3, 2f)
Smashing on the keyboard while having a lua file opened in some text editor.
+
  
Ways to fix: Remove the malformed number.
+
'''Possible causes:'''
 +
* An IP address was written as a number instead of a string
 +
* Incorrect writing of multiplication of a number and a variable
  
 +
'''Ways to fix:'''
 +
* Store IP addresses as a string
 +
* Multiply variables with numbers by using the '''*''' operator
  
== Unexpected symbol near 'symb' ==
 
  
Fix difficulty: Easy
+
== Unexpected symbol near 'symbol' ==
  
Description: You typed a symbol in the code that Lua didn't know how to interpret.
+
'''Description:''' You typed a symbol in the code that Lua didn't know how to interpret.
  
Possible causes:  
+
'''Possible causes:'''
You didn't respect the syntax of a structure (IE. you forgot a 'then' after an 'if').
+
* Incorrect syntax (e.g. Forgot to write "then" after an if statement)
You used an uneven number of brackets or closed them at the wrong places.
+
* Not closing brackets and parenthesis at the correct locations
You're using the wrong kind of operator (IE. '=' instead of '==').
+
  
Ways to fix: Be on the look out for any characters you typed in by accident.
+
'''Ways to fix:'''
 +
* Make sure there are no mistypes in the code
 +
* Close brackets and parenthesis correctly (See: Code Indentation)
  
 +
== 'symbol1' expected near 'symbol2' ==
 +
'''Description:''' Lua expected symbol1 instead of symbol2
  
== NOTE: ==
+
'''Possible causes:'''
 +
* Not closing all brackets and parenthesis before the end of the file
 +
* Wrong operator calling (e.g. "==" instead of "=")
  
Taken from [https://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/indexbfbb.html here]
+
'''Ways to Fix'''
 +
* Close brackets and parenthesis correctly (See: Code Indentation)
 +
* Use the correct operators
  
--[[User:KillZone|KillZone]] 18:27, 18 April 2017 (UTC)
+
[[Category:Lua_Reference]]

Revision as of 14:09, 24 June 2017

Contents

Attempt to call a nil value

Description: You tried to call a function that doesn't exist.

Possible causes:

  • Your function might be defined in another lua state. (e.g Calling a function on the client that only exists on the * server.)
  • You're using a metafunction on the wrong kind of object. (e.g. Calling :SteamID() on a Vector)
  • The function you're calling has an error in it which means it is not defined.
  • You've misspelled the name of the function.

Ways to fix:

  • Make sure the function exists
  • Make sure your function is defined in the correct realm
  • Check your function calls for spelling errors


Attempt to perform arithmetic on global '?' (a nil value)

Description: You tried to perform arithmetic (+, -, *, /) on a global variable that is not defined.

Possible causes:

  • You tried to use a local variable that was defined later in the code
  • You've misspelled the name of the global variable

Ways to fix:

  • Make sure you define local variables before calling them in the code
  • Check for spelling errors

Attempt to perform arithmetic on '?' (a type value)

Description: You tried to perform arithmetic (+, -, *, /) on a variable that cannot perform arithmetic. (e.g. 2 + "some string")


Attempt to index global 'varname' (a nil value)

Description: You tried to index an undefined variable (e.g. print( variable.index ) where variable is undefined)

Possible causes:

  • The variable is defined in a different realm
  • The variable is local and defined later in the code
  • You've misspelled the name of the variable

Ways to fix:

  • Make sure the variable is only accessed in the realm it was defined in
  • If the variable is local, define it before accessing it

Malformed number near 'number'

Description: There is a malformed number in the code (e.g. 1.2.3, 2f)

Possible causes:

  • An IP address was written as a number instead of a string
  • Incorrect writing of multiplication of a number and a variable

Ways to fix:

  • Store IP addresses as a string
  • Multiply variables with numbers by using the * operator


Unexpected symbol near 'symbol'

Description: You typed a symbol in the code that Lua didn't know how to interpret.

Possible causes:

  • Incorrect syntax (e.g. Forgot to write "then" after an if statement)
  • Not closing brackets and parenthesis at the correct locations

Ways to fix:

  • Make sure there are no mistypes in the code
  • Close brackets and parenthesis correctly (See: Code Indentation)

'symbol1' expected near 'symbol2'

Description: Lua expected symbol1 instead of symbol2

Possible causes:

  • Not closing all brackets and parenthesis before the end of the file
  • Wrong operator calling (e.g. "==" instead of "=")

Ways to Fix

  • Close brackets and parenthesis correctly (See: Code Indentation)
  • Use the correct operators
Personal tools
Navigation