Page 1 of 1

Trying to update mod to 2.0

Posted: Sun Oct 27, 2024 11:03 am
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>

Re: Trying to update mod to 2.0

Posted: Sun Oct 27, 2024 11:45 am
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

Re: Trying to update mod to 2.0

Posted: Sun Oct 27, 2024 12:54 pm
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.

Re: Trying to update mod to 2.0

Posted: Sun Oct 27, 2024 1:37 pm
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.

Re: Trying to update mod to 2.0

Posted: Sun Oct 27, 2024 2:32 pm
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.

Re: Trying to update mod to 2.0

Posted: Tue Oct 29, 2024 8:07 am
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`.

Re: Trying to update mod to 2.0

Posted: Tue Oct 29, 2024 10:14 am
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!