ModMash


New Planets, Late game enemy, Land Mines, Underground world, Subways, Valkyries, Ore refining, Crash Site Items and Tech Loot, Subspace Transport, Sub-Dimensional Stacking, Biter harvesting. Placeable spawners, Alien Ooze, Ore Enrichments, conversions, Regenerative Walls and Belts, Recycler, Fluid controls, Mini Boiler, Fishing Machine, Mini Loaders. Titanium Walls, pipes and Belts, Biter Neural Toxin, Fish and Ooze juice. This is a modpack for all splinters.

Overhaul
2 years ago
0.16 - 1.1
4.08K

g Small request of help

Honktown β˜†
4 years ago

I was wondering how you got stack_size for the loot chests. I have been struggling with how to know an item has stack_size in game.item_prototypes, outside of just knowing in advance. If one tries to access a nil value you get an error and the current game quits to the main menu. I have a way of tracking stack_size and if any other value exists from data-final-fixes to during-the-game , but it's definitely not the right way.

I took a look at your code but I'm having a hard time following where the stack_size is coming from.

4 years ago
(updated 4 years ago)

This should work, modified from my code

local local_get_stack_size = function(name)
if data.raw["item"][name] ~= nil then
local stack_size = data.raw["item"][name].stack_size
if stack_size ~= nil then return stack_size end
end
return 50 --make something up
end

in game you can use game.item_prototypes[name] I guess

Other than that loop though all the item groups check name and stack_size if both valid record in a table for later use.

Honktown β˜†
4 years ago

Yeah, during the game is where I am having trouble... I tried recording data during data-final-fixes but maybe I was doing it wrong, because I couldn't access any later.

4 years ago

So replace data.raw with game.item_prototypes should work

Honktown β˜†
4 years ago

If you even READ a nil, it throws an error and exits to the main menu. They removed iterator functions, so you can't check the keys/values. There's a way around it, and I'm not going to tell them. They'll figure it out eventually.

4 years ago

???.. yep there is always a way. I was getting nil recipes wich was doing somthing like that because of commas at the end of tabe entries. guess one other thing you could do is wrap it in a pcall and hope to catch the exception. But anyway ill see what you've done later on to remedy it.

This thread has been locked.