Page 1 of 1

Modding error

Posted: Thu Mar 03, 2016 8:39 pm
by Vanra
Greetings,

I've been playing this game since I bought it on Steam about a day or two ago and gotten completely addicted to it.

Seeing as I'm studying to become a programmer, I thought I'd give modding this game a try, yet I seem to have hit a wall.

For some reason, try to generate a new map or load a previous one, I get the same error:

Code: Select all

control.lua:14:LuaBootstrap doesn't contain key oninit.
I get that my error is on (or has something to do with) line 14, yet as far as I see and understand there is nothing wrong with it:

Code: Select all

script.oninit(function() OnInit() end)
Thank you for any help in advance.

Re: Modding error

Posted: Thu Mar 03, 2016 8:40 pm
by daniel34
The event is called script.on_init (notice the underline):
https://wiki.factorio.com/index.php?tit ... pt.on_init

In case you haven't seen it yet, there is also a folder named doc-html in the Factorio program folder that contains the documentation to the modding API.

Re: Modding error

Posted: Thu Mar 03, 2016 8:57 pm
by Vanra
Thank you, I must've had C++ stuck in my mind somewhere, that did fix it.

And I missed the documentation completely. I'll be working my way though it now!

Thanks again!

Re: Modding error

Posted: Thu Mar 03, 2016 9:24 pm
by Vanra
Sadly enough I am getting a new error code now, one that I had to fix before, but this time it seems to be an issue somewhere else...

Code: Select all

Unknown key:"Error while running the on_init: .../control.lua:24:attempt to index global 'glob' (a nil value)"
Here is the code that should give the error.

Code: Select all

function OnInit()
	game.player.print("SmartSplitters: OnInit")
	if glob.sspl == nil then
		glob.sspl = {	splitSets = {},
						splitSetsToRemove = {},
						version = utils.currentVersion
					}
	else
		local total = 0
		for _, set in pairs(glob.sspl.splitSets) do
			total = total + #set.splitters
		end
		
		--game.player.print("Loaded " .. #glob.sspl.splitSets .. " splitter sets containing " .. total .. " splitters.")
	end
	if not glob.sspl.version then
		game.player.print("Migrating SmartSplitters from unversioned to version " .. utils.currentVersion)
		utils.migrations.versionless()
		game.player.print("Migration successful.")
	end
	if glob.sspl.version ~= utils.currentVersion then
		game.player.print("Migrating SmartSplitters from version " .. glob.sspl.version .. " to version " .. utils.currentVersion .. ".")
		utils.migrations[glob.sspl.version]()
		game.player.print("Migration successful.")
	end
end

Re: Modding error

Posted: Thu Mar 03, 2016 10:10 pm
by prg
Version 0.12.0 changelog wrote:
  • Changed glob to global.

Re: Modding error

Posted: Fri Mar 04, 2016 1:46 pm
by Vanra
Error 3:

I've tried looking it up and can't seem to find anything about it since most refer to the global version of this error.

Code: Select all

control.lua:228: attempt to index local '_Entity' (a nil value)
As for the code from line 227 to 229:

Code: Select all

function IsSmartSplitter(_Entity)
	return (_Entity.name == "Smart Splitter")
end
Thank you for your time.

Re: Modding error

Posted: Fri Mar 04, 2016 2:03 pm
by prg
So whatever calls this function passes nil instead of an entity. Find out where that happens.

Re: Modding error

Posted: Fri Mar 04, 2016 2:15 pm
by Vanra
The function gets called in 3 cases, when it is destroyed, mined or on build... I am guessing, since it happens when I put anything down it will have to do with the on build.

Code: Select all

function OnBuiltEntity(_Event)
local _Entity = _Event.createdentity
if IsSmartSplitter(_Entity) then
...
Which get called here:

Code: Select all

script.on_event(defines.events.on_built_entity, function(event) OnBuiltEntity(event) end)

Re: Modding error

Posted: Fri Mar 04, 2016 2:20 pm
by prg
So it's a missing underscore again, this time in createdentity.

Re: Modding error

Posted: Fri Mar 04, 2016 2:21 pm
by Vanra
I'll go be ashamed in a corner right now... Sorry about that.