Page 1 of 1

Reading Control.lua errors

Posted: Tue Feb 28, 2017 6:49 pm
by Tron842
I apologise if this question has already been answered. I did a few quick searches for the answer and came up with nothing. When writing code in control.Lua (or I suppose any Lua file executed by factorio) is there a way to see the error that has been thrown? (are there errors getting thrown?)

For now, i have just been inserting a log message between lines I believe are the offending errors but as you can imagine it becomes quite tedious.

Thank you guys in advance for any help

Re: Reading Control.lua errors

Posted: Tue Feb 28, 2017 6:56 pm
by Rseding91
You see any error thrown when it pops up and displays the error message with an "ok" button. It shows the line number and stack trace + what the error was.

Re: Reading Control.lua errors

Posted: Tue Feb 28, 2017 7:07 pm
by Tron842
Sorry, i guess I worded my question a bit poorly. Maby an example will help say I had the following script:

Code: Select all

Event.register({defines.events.on_built_entity, defines.events.on_robot_built_entity}, function(event)
    local entity = event.created_entity
    local name = emtity.name
    ...
end
If I were to run this code the game would get to the 2nd line and then just stop. A simple error to make but hard to check if the logic is broken or if you made a simple mistake. It can take a long time to fix trivial mistakes. Thank you for the response, though.

Re: Reading Control.lua errors

Posted: Tue Feb 28, 2017 7:21 pm
by Rseding91
Tron842 wrote:Sorry, i guess I worded my question a bit poorly. Maby an example will help say I had the following script:

Code: Select all

Event.register({defines.events.on_built_entity, defines.events.on_robot_built_entity}, function(event)
    local entity = event.created_entity
    local name = emtity.name
    ...
end
If I were to run this code the game would get to the 2nd line and then just stop. A simple error to make but hard to check if the logic is broken or if you made a simple mistake. It can take a long time to fix trivial mistakes. Thank you for the response, though.
It would give you an error that said something along the lines of "error at line *line number*: Attempt to index 'emtity' a nil value."

Re: Reading Control.lua errors

Posted: Tue Feb 28, 2017 8:04 pm
by Tron842
Hmm, well I had to test to make sure I wasn't going crazy. I tested what I said and the game just stopped running the script and carried on its way. Didn't print any error message that I can find (neither a pop-up of in the factorio-current.log.

Re: Reading Control.lua errors

Posted: Tue Feb 28, 2017 8:20 pm
by Rseding91
Tron842 wrote:Hmm, well I had to test to make sure I wasn't going crazy. I tested what I said and the game just stopped running the script and carried on its way. Didn't print any error message that I can find (neither a pop-up of in the factorio-current.log.

Code: Select all

Event.register({defines.events.on_built_entity, defines.events.on_robot_built_entity}, function(event) ... end)
This isn't valid event registration syntax. It's:

Code: Select all

/c script.on_event({defines.events.on_built_entity, defines.events.on_robot_built_entity}, function(event) ... end)
Or if done in control.lua you don't include the /c

When I test it, it works just fine:
Capture.PNG
Capture.PNG (75.02 KiB) Viewed 2904 times

Re: Reading Control.lua errors

Posted: Tue Feb 28, 2017 8:38 pm
by Tron842
I changed how the event was regestered as you suggested and it gave me the error. I didn't even realize there was multiple ways to regester events and will switch to this one. Thankyou

Re: Reading Control.lua errors

Posted: Tue Feb 28, 2017 8:42 pm
by Tron842
Darn I am an idiot. There isn't I was just useing someone's libary and didn't see theit events code.... there isn't two ways sigh pleas excuse my ignorance.