[Answered] Player inventory concurrent modification woes

Place to get help with not working mods / modding interface.
Post Reply
Timeslice
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Thu Aug 13, 2015 7:27 pm
Contact:

[Answered] Player inventory concurrent modification woes

Post 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.
Last edited by Timeslice on Fri Oct 21, 2016 11:13 pm, edited 1 time in total.

User avatar
aubergine18
Smart Inserter
Smart Inserter
Posts: 1264
Joined: Fri Jul 22, 2016 8:51 pm
Contact:

Re: Player inventory concurrent modification woes

Post 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
Better forum search for modders: Enclose your search term in quotes, eg. "font_color" or "custom-input" - it prevents the forum search from splitting on hypens and underscores, resulting in much more accurate results.

Timeslice
Long Handed Inserter
Long Handed Inserter
Posts: 75
Joined: Thu Aug 13, 2015 7:27 pm
Contact:

Re: Player inventory concurrent modification woes

Post by Timeslice »

Excellent. Thanks :)

Post Reply

Return to “Modding help”