[NFP] Understanding Error Messages for Novices Like Myself

DeckerdJames

Chieftain
Joined
Nov 1, 2019
Messages
93
Please feel free to add to this. I am still learning.
I think I understand the stack trace, now.

Consider this error message in the Lua console:
Code:
 Runtime Error: C:\Users\James\Documents\My Games\Sid Meier's Civilization VI\Mods\Camera\Camera_GamePlayScript.lua:134: function expected instead of nil
stack traceback:
    C:\Users\James\Documents\My Games\Sid Meier's Civilization VI\Mods\Camera\Camera_GamePlayScript.lua:134: in function 'ClockInVT'
    C:\Users\James\Documents\My Games\Sid Meier's Civilization VI\Mods\Camera\Camera_GamePlayScript.lua:158: in function 'SetupFirstVT'
    C:\Users\James\Documents\My Games\Sid Meier's Civilization VI\Mods\Camera\Camera_GamePlayScript.lua:296: in function 'Initialize'
    C:\Users\James\Documents\My Games\Sid Meier's Civilization VI\Mods\Camera\Camera_GamePlayScript.lua:301: in function '(main chunk)'
    [C]: in function '(anonymous)'
Lua callstack:

To generate this error, I changed a letter in a function call that sets a property on an object. I changed the name of the function from 'SetProperty' to 'Setproperty'. Since function names are case sensitive, the lower case 'p' changes what function should be called. Since that function does not exist the error generated is:
Code:
[CODE] Runtime Error: C:\Users\James\Documents\My Games\Sid Meier's Civilization VI\Mods\Camera\Camera_GamePlayScript.lua:134: function expected instead of nil

It got nil instead of a function because 'Setproperty' was never declared as a function, so it doesn't exist.

The stack trace, the 5 lines below the error line, will be in a particular order and they represent the execution path. The top line is the function that the error occurred inside of.
Code:
C:\Users\James\Documents\My Games\Sid Meier's Civilization VI\Mods\Camera\Camera_GamePlayScript.lua:134: in function 'ClockInVT'

The function that called ClockInVT is the next line:
Code:
 C:\Users\James\Documents\My Games\Sid Meier's Civilization VI\Mods\Camera\Camera_GamePlayScript.lua:158: in function 'SetupFirstVT'

this continues through the Initialize() function, so this error happened when the script was being first loaded
Code:
C:\Users\James\Documents\My Games\Sid Meier's Civilization VI\Mods\Camera\Camera_GamePlayScript.lua:296: in function 'Initialize'

The (main chunk) are the statements in the Lua script that are not inside function declarations, such as event subscriptions and the Initialize() function call.
Code:
Events.UnitMoved.Add(OnUnitMoved) -- this statement is in the (main chunk)

function Initialize()
    --do stuff
end
Initialize() -- this statement is in the (main chunk)

The last part of the stack trace is the '(anonymous)' function. This is the function that called your Lua script. It is part of the game engine coded by Firaxis.
Code:
 [C]: in function '(anonymous)'

As usual, I must admit I am still on the learning curve. If any experts see something wrong with this, please, feel free to correct it.
 
Top Bottom