Errors



Are you having trouble understanding the error message in PICO-8? Or do you want to know how to start to debug such an error? This debugging resource was made for just those purposes!


How to Read Error Messages

First of all, let's understand how to read the PICO-8 Error Messages and breakdown its parts. This is an example of a PICO-8 error message:

syntax error line 9 (tab 0)
		erroring here
syntax error near 'here'
in _update line 17 (tab 0)

The first line of the errors usually start with either:

SYNTAX ERROR A problem with breaking code structure or rules.
RUNTIME ERROR A problem found while trying to run your game.

Then it will tell you where in your code it found this problem, not necessarily where the real problem is, just where it was noticed. 

LINE _ (TAB _ ) = The line number and code tab number in the PICO-8 editor

On the next line of the error message, it will print the exact line of code where the error occurred (again, that's not always where the problem actually is). In the above example, the words "erroring here" are taken from the code where the error was triggered.

The next line of the error message is the specific type of error that happened and what word or symbol on that line of code it is near. Sometimes this points directly to the problem, often times it just gets you closer to the real problem. You can look up your error type in the list on this page.

SYNTAX ERROR NEAR 'HERE' = Type of error and it was triggered near this word or symbol

Sometimes you'll see even more information given about the error in indigo. This is a breadcrumb trail starting at where the error occurred and working backwards to tell you what function(s) that line is in. This can be helpful because the real problem could be in one of the parent functions, not in the line that triggered the error.


Types of Errors

We have gathered a list of known error messages we have seen in PICO-8 and provided both a better description of what the error is, and some possible steps to finding solutions to fix them.



Error Message Read How to Debug
<eof> Debug
unfinished string Debug
malformed number Debug
attempt to perform arithmetic Debug
attempt to concatenate field Debug
unclosed ... Debug
'a' expected near 'b' Debug
unexpected symbol near 'a' Debug
attempt to call Debug
attempt to index Debug



End of File


"EOF" stands for "End of File" which means that PICO-8 reached what was expected to be the final end, but there was more code after that point. 

Example:

function _draw()
	if a then
		if b then --errors here
		end
	end
end

end --extra end here

How to Debug:  Find and remove one or more extra ENDs. It may not be where the error points to, so carefully go through your code to match each END to its "opening" until you find the END that does not have a match.




Unfinished String


Strings must start and end with quotation marks, either double quotes ("string") or single quotes ('string'). This error has detected a string that you either started or ended but has a missing quotation mark to the pair.

Examples:

name = "billy

name = billy"

How to Debug: Find and add the missing quotation mark matching the one shown in the error.




Malformed Number


"Malformed" means "created incorrectly" and refers to a number data type that it recognizes as trying to be a number but it is not able to resolve into a well formed number. Common causes could be using more than one decimal point, or attempting to concatenate (..) incorrectly. If you try concatenating a string by starting with a number, it will also error, so it is better to put that number in a variable or quotes.

Examples:

num = 1.2.3

num = 1..2.."3"

num = 123.."abc"

How to Debug: This error usually does a good job about pointing directly to your problem. Find the buggy number and make it a true number.




Attempt to Perform Arithmetic


This error shows when something goes wrong when trying to do math, usually with variables that are not numbers. The full error will explain what the value is instead, such as "attempt to perform arithmetic on [variable] (a nil value)" which means that it cannot find that variable and it does not hold a number value. It might also say "(a string value)" even though PICO-8 will attempt to convert strings to numbers first, any string that cannot be converted will trigger this error.

Examples:

math = 1 + a

math = 1 + "a"

How to Debug: This error usually does a good job about pointing directly to your problem. Find the buggy variable and make sure what you are trying to do math with are all number data types.




Attempt to Concatenate


"Concatenate" means "to put together in a connected series, like a chain". This error means that something went wrong while trying to use the (..) string operator, explained here. If you try to concatenate a variable that is nil, a boolean, or a function, then it will trigger this error. If trying to concatenate a number directly (not in a variable), then you must put the digits inside of quotation marks to make it a string first. On the other hand, if the variable you are concatenating is holding a number value, then PICO-8 will automatically first convert it to a string for you, which is why number variables can be concatenated.

Example:

string = "abc"..a

string = "abc"..true

string = "abc"..print

How to Debug: Find the line where you are concatenating a string, and double check all of the values are strings already. You may need to use tostr() to convert your value to a string before concatenating it.




Unclosed


An "unclosed..." error means that some block of code is not properly closed (ended).  This error is specified to be one of these issues:

UNCLOSED IF If statement does not having a matching end
UNCLOSED FUNCTION A function does not have an end
UNCLOSED FOR A for loop does not have an end
UNCLOSED WHILE A while loop does not have an end

Example:

if a then

function b()

for c=0,10 do

while d do

How to Debug: This error usually does a good job about pointing to the correct problem, but you should double check, especially for nested blocks of code. Match each END "closing" to its "opening" to find the one that is missing and add it in the correct place. Proper code formatting through indentation will help make this search easier, and prevent you from making this mistake in the future.




Expected


This error tells you what word or symbol is expected near what part of the line of code. Certain key words or symbols go together to form proper code syntax (basically the grammar rules of the coding language). If statements usually require a "then". Loops usually require a "do". Tables require "{" and "}" and commas "," between values. Forgetting these are common mistakes that will trigger this error. Less commonly, it could say <name> expected, which means there is a missing variable name that it expects.

Remember that "elseif" requires "then" even though "else" does not have a condition nor a "then" and only write one "end" for an "if" statement, no matter how many "elseif" are in between.

Examples:

if a end
--'then' expected after if

if a then
elseif b
else
end
--'then' expected after elseif

for i=0,10   end
--'do' expected after for

table = { a,b c d }
--'}' expected near c
--missing commas

How to Debug: Start with where the error points and look for the word or symbol that it says it is expecting to find where that word or symbol is missing. Sometimes you do have what it expects in your code but it may expect it earlier than you have it, so the bug may be something else in between such as a table having the closing brace but missing commas.




Unexpected


This error is quite common because it covers many different possible bugs. In general, it tells you that a word or symbol is just in the wrong place according to the code's syntax (structure rules) but it could be either something is added unnecessarily, or something is missing that causes the next word or symbol to come earlier than expected. To avoid this error, it just takes a clear understanding of the syntax rules, and that comes from either a lot of reading, or a lot of practice. So if you are seeing this error a lot, it may be difficult to find the problem and fix it, but with more experience, you'll come across this error less and less.

Example:

if then a=10 end
--missing condition

table =. b
--unnecessary symbol

How to Debug: Read through the code at the line the error points to, considering syntax rules for every word and symbol to find what is there unexpectedly or what is missing. Take the time to study and learn the rule that has been broken so you don't make the same mistake in the future. Often times, an experienced programmer can identify the problem quickly, so you can share your code and the error and ask for help, but don't just fix the code, take the time to understand the problem so you can identify it yourself next time.




Attempt to Call


This error means that the code tries to run a function ("call" it) but cannot find the function it is being asked to call. This can happen with mistyped function names, or calls to a function occurring before the function is declared. If you have any functions that you want to run during the initialization of your game, then make sure to put the call inside of _init() which will make sure that the functions are all declared before _init() gets run. If your call is outside of any function, it will try to run that before _init(). Understanding the order that your code is run is especially important when you start preparing multiple scenes.

Example:

a=10

a()
--a is not a function

b()
--b is not yet declared

function b() print("hi") end

How to Debug: Find all cases where you are trying to run the function and double check that it is spelled correctly. Then make sure that in the order of running your game, the function gets declared before you try to call it. Then make sure you are not overwriting the function between declaring it and calling it. Know that function names are no different from variable names in Lua, so it is important to avoid using function names as your variable names.


Attempt to Index


This error means that PICO-8 tried to find an element of a table but couldn't find either the whole table or the key in that table. It will usually state what data type is when it is not able to access the table such as "attempt to index 'tbl' (a nil value)" or "(a number value)". Less commonly, the error may say "(for compound)" possibly meaning that a for loop is involved, but we are looking for more information on this specific error.

Examples:

a[1] = 10
--"a" is not defined yet

a = {1,2,3}
for b in all(a) do
	b.health+=1
end
--"a" is not an object for "b" to be a table

for e in all(enemies) do
	e.x+=1
end
e.y+=1
--"e" is not a table outside loop

How to Debug: Find the variable that it is trying to index and make sure that it is a table. Also make sure that the table is accessible where you are trying to retrieve a value from it. A common mistake is trying to use a local table created by for var in all() loop, outside of that loop.



Images in this Guide by NerdyTeachers is licensed under CC BY-SA 4.0

72

1 Jan 2025

Font