Trying to update mod to 2.0

Place to get help with not working mods / modding interface.
User avatar
fishycat
Filter Inserter
Filter Inserter
Posts: 315
Joined: Thu Apr 09, 2015 7:38 pm
Contact:

Trying to update mod to 2.0

Post by fishycat »

I have this mod Loot-Chest-Plus trying to work with 2.0. But somehow my guerrilla-coding-skills don't suffice and any help is appreciated.

What I did so far:
- I changed all global to storage
- changed the recipe to the new format
- set up a github page

When I place the chest, there are no more errors, but also no loot-collecting. I get an error when I place down two chests, since only one is allowed
The error:

Code: Select all

Error while running event LootChestPlus::on_built_entity (ID 6)
__LootChestPlus__/control.lua:146: Arguments count error for 'spill_item_stack': Expected 1 argument but 4 were given
stack traceback:
	[C]: in function 'spill_item_stack'
	__LootChestPlus__/control.lua:146: in function 'handleBuiltLootChest'
	__LootChestPlus__/control.lua:110: in function <__LootChestPlus__/control.lua:107>
robot256
Smart Inserter
Smart Inserter
Posts: 1063
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Trying to update mod to 2.0

Post by robot256 »

Many other API methods have changed. spill_item_stack now takes a table of named parameters, so you will have to reformat the function call. See https://lua-api.factorio.com/latest/cla ... item_stack
User avatar
fishycat
Filter Inserter
Filter Inserter
Posts: 315
Joined: Thu Apr 09, 2015 7:38 pm
Contact:

Re: Trying to update mod to 2.0

Post by fishycat »

Thanks for the link, I got it to work now after some try and error with this change

Code: Select all

game.players[1].print("You can place only one loot chest!")
		chest.surface.spill_item_stack{position=chest.position, stack={name = "artifact-loot-chest", amount = 1}, true, chest.force}
		chest.destroy()
It now correctly spills the chest as item on ground when another chest is already placed.

What remains is, the chest won't collect loots if an entity dies.
robot256
Smart Inserter
Smart Inserter
Posts: 1063
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Trying to update mod to 2.0

Post by robot256 »

You'll have to check the api functions and events in the rest of the code versus the docs to see if any of them changed too. Not sure what it uses to find items to loot.
User avatar
fishycat
Filter Inserter
Filter Inserter
Posts: 315
Joined: Thu Apr 09, 2015 7:38 pm
Contact:

Re: Trying to update mod to 2.0

Post by fishycat »

I suspect the https://lua-api.factorio.com/latest/cla ... t_contents part, but not sure. I have no clue what it wants from me. There are no errors.
robot256
Smart Inserter
Smart Inserter
Posts: 1063
Joined: Sun Mar 17, 2019 1:52 am
Contact:

Re: Trying to update mod to 2.0

Post by robot256 »

You are on the right track. LuaInventory::get_contents() changed to include item quality. Now, instead of returning a table indexed by itemName and returning the numeric quantity, it returns array indexed by integers and returning a table for each item/quality combination. The table contains "name", "quality", and "count".

Looking at the code in LootChest, it will be a little tricky to account for quality. To ignore quality completely, all you need to do is change line 40 to `lootCount = value.count` and line 41 to 'itemName = value.name`.
User avatar
fishycat
Filter Inserter
Filter Inserter
Posts: 315
Joined: Thu Apr 09, 2015 7:38 pm
Contact:

Re: Trying to update mod to 2.0

Post by fishycat »

Thanks for taking the time, I changed the two lines and tested it with my Alien-space-science mod. Got an error

Code: Select all

Error while running event LootChestPlus::on_entity_died (ID 4)
__LootChestPlus__/control.lua:43: attempt to get length of global 'lootCount' (a number value)
stack traceback:
	__LootChestPlus__/control.lua:43: in function <__LootChestPlus__/control.lua:30>

Something with line 43 where it asks a numeric value. How do I get the length of global 'lootCount' there correctly?


edit: after I changed line 43 from

Code: Select all

if #lootCount > 0 then
to

Code: Select all

if lootCount > 0 then
I'm cautiously optimistic it works now. Either way, I very much appreciate your help!
Post Reply

Return to “Modding help”