Reading Control.lua errors

Place to post guides, observations, things related to modding that are not mods themselves.
Post Reply
Tron842
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu Feb 16, 2017 4:14 am
Contact:

Reading Control.lua errors

Post 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

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Reading Control.lua errors

Post 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.
If you want to get ahold of me I'm almost always on Discord.

Tron842
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu Feb 16, 2017 4:14 am
Contact:

Re: Reading Control.lua errors

Post 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.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Reading Control.lua errors

Post 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."
If you want to get ahold of me I'm almost always on Discord.

Tron842
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu Feb 16, 2017 4:14 am
Contact:

Re: Reading Control.lua errors

Post 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.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Reading Control.lua errors

Post 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 2828 times
If you want to get ahold of me I'm almost always on Discord.

Tron842
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu Feb 16, 2017 4:14 am
Contact:

Re: Reading Control.lua errors

Post 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

Tron842
Burner Inserter
Burner Inserter
Posts: 12
Joined: Thu Feb 16, 2017 4:14 am
Contact:

Re: Reading Control.lua errors

Post 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.

Post Reply

Return to “Modding discussion”