Spectrus
03-12-2014, 11:35 PM
Quick tutorial today explaining script errors and how to diagnose issues in your script. I've seen far too many threads where eople are asking for help when the error message is pretty clear on what is wrong.
Here is an example of an error:
16:22 XenoScript Error:
Script: tut.lua
Line #: 1
Chunk: C:?Users?Spectrus?Documents?XenoBot?Scripts?tut.lu a
Error: attempt to call global 'Print' (a nil value)
This is an error with user-input and should not be reported as a bug with XenoBot.
You can see it tells you some information about the 'Script', the 'Line', the 'Chunk', and the 'Error'.
The 'Script' is the file that crashed as a result of the error.
The 'Line' is the line of code that is causing the error (NOTE: This is not always in the 'Script' file.)
The 'Chunk' is the path to the file that caused the error (NOTE: Not always the same as the 'Script' file.)
The 'Error' is what is wrong.
The reason that the Line and Chunk do not always correspond to the Script file is that scripts can rely on other files (i.e. through dofile() or the native library). The most common issue that I've seen when the Line/Chunk do not line up with the Script is where bad parameters are being passed to a function in the native library (C:/Program Files/Xenobot/Data/XenoLuaLib.lua). You can open the native library, go to the specified line, see what function it is a part of, then go back to your script and make sure any calls to that function are proper.
Regarding understanding the Error message: In the example, it says it is attempting to call a function called "Print", which is a nil value (doesn't exist). The reason for this is that the print function is has a lowercase 'p'. Functions are case sensitive, make sure you have the right casing. If the error is similar but says attempt to 'index' instead of 'call' then it is referring to a variable.
There are many other types of error messages, most of which can be understood by simply reading it and then looking at the line of code it is tied to. If there are any error messages that you can't understand you can post them in this thread and I will do my best to help. Please post them wrapped in [code] tags ([code][ /code]).
With all of this said, please stop posting requests for help before reading the error message and trying to understand.
Here is an example of an error:
16:22 XenoScript Error:
Script: tut.lua
Line #: 1
Chunk: C:?Users?Spectrus?Documents?XenoBot?Scripts?tut.lu a
Error: attempt to call global 'Print' (a nil value)
This is an error with user-input and should not be reported as a bug with XenoBot.
You can see it tells you some information about the 'Script', the 'Line', the 'Chunk', and the 'Error'.
The 'Script' is the file that crashed as a result of the error.
The 'Line' is the line of code that is causing the error (NOTE: This is not always in the 'Script' file.)
The 'Chunk' is the path to the file that caused the error (NOTE: Not always the same as the 'Script' file.)
The 'Error' is what is wrong.
The reason that the Line and Chunk do not always correspond to the Script file is that scripts can rely on other files (i.e. through dofile() or the native library). The most common issue that I've seen when the Line/Chunk do not line up with the Script is where bad parameters are being passed to a function in the native library (C:/Program Files/Xenobot/Data/XenoLuaLib.lua). You can open the native library, go to the specified line, see what function it is a part of, then go back to your script and make sure any calls to that function are proper.
Regarding understanding the Error message: In the example, it says it is attempting to call a function called "Print", which is a nil value (doesn't exist). The reason for this is that the print function is has a lowercase 'p'. Functions are case sensitive, make sure you have the right casing. If the error is similar but says attempt to 'index' instead of 'call' then it is referring to a variable.
There are many other types of error messages, most of which can be understood by simply reading it and then looking at the line of code it is tied to. If there are any error messages that you can't understand you can post them in this thread and I will do my best to help. Please post them wrapped in [code] tags ([code][ /code]).
With all of this said, please stop posting requests for help before reading the error message and trying to understand.