Page 1 of 1

[Answered] Player inventory concurrent modification woes

Posted: Fri Oct 21, 2016 10:56 pm
by Timeslice
I'm having an issue when multiple mods are loaded that alter the player's inventory during on_player_created. I have a few mods which add items to the player's inventory on start, and one which clears the player inventory on start. I'm not having any actual runtime errors, but I'm looking for a simple way to ensure that the mod which clears the player inventory always goes last.

Currently the control.lua is this:

Code: Select all

script.on_event(defines.events.on_player_created, function(event)
	local a_player = game.players[event.player_index]
	for i=1,6,1 do
		a_player.get_inventory(i).clear()
	end
end)
I was initially thinking of having some kind of sleep at the top of the event handler function, but that seems like a rather hacky way to get the job done. Sadly, adding optional mod dependancies didn't seem to help at all.

Re: Player inventory concurrent modification woes

Posted: Fri Oct 21, 2016 11:06 pm
by aubergine18
Currently events are triggered in mods based on the alphabetical order of the mods name. So a mod with name "XYZ" will get its events after a mod with name "ABC".

This is planned to change in 0.15 release so that events respect mod dependencies. Once that change is in place, you'd be able to add optional dependencies to your mod (those that get ? in their list of depdendencies) to ensure your mod loads after the others it optionally depends on and thus get its events last.

More infos: viewtopic.php?p=215849

Re: Player inventory concurrent modification woes

Posted: Fri Oct 21, 2016 11:13 pm
by Timeslice
Excellent. Thanks :)