Page 1 of 2

Storage tank max size info

Posted: Thu Dec 18, 2014 1:05 pm
by Kexík
Hi, i was trying to reach Storage tank max size (fluid_box.base_area) from code but without success. I know that i can get to prorotype of entity, but it seem that i need to cast it somehow to specific entityType to be able reach fluid_box.
Am i right and is it possible in lua? Or am i doing it wrong. please help, I hate using hardcoded magic numbers. :)

BTW isnt here something like Modders irc where i could ask about simple problem like this and dont spam forum?

Re: Storage tank max size info

Posted: Thu Dec 18, 2014 6:18 pm
by n9103
Kexík wrote:BTW isnt here something like Modders irc where i could ask about simple problem like this and dont spam forum?
That would require people to regularly log into something, something I find relatively rare, even when the whole process can be automated.

Re: Storage tank max size info

Posted: Thu Dec 18, 2014 9:01 pm
by L0771
Kexík wrote: I hate using hardcoded magic numbers.
Me too.

According to what I understand, you want ask "base_area" of an tank entity or pipe in your control.lua
This theoretically is entity.prototype.fluid_box.base_area, but can't be get some properties, i think you need hardcode magic numbers :/

Re: Storage tank max size info

Posted: Thu Dec 18, 2014 10:16 pm
by drs9999
If what L0771 said don't work, then I'm pretty sure that there is no way to do it.

However maybe you want to explain why you need it, there might be other solutions.

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 12:23 pm
by Kexík
I need exactly what L0771 said entity.prototype.fluid_box.base_area, but problem is that entity.prototype give me Prototype/Entity and that dont have fluid_box so i would need to recast it somehow to Prototype/PipeConnectable that have fluid box so i can reach it. Thats what i think is the problem.

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 1:02 pm
by drs9999
Well yes, but that isn't working, right?! There is nothing like casting in this context, so if you can't access it that means that you can't access it ;)

Anyway, there still exist workarounds like "meta-items". Basically you create generic items in the loading phase which store the values in which you are intrested, in keys that are accesible via the prototype.

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 1:53 pm
by Kexík
Hmm thanks, about that workaround, you mean like, when prototypes are loaded i will save their base_area for example like myTable[prototype.name] = prototype.liquid_box.base_area (with all necessary checks of course), but where can i do it? Do you have any example or link where is mentioned how to do it?

BTW i want this because of compatibility with other mod if they create storage-tank type entity with different base_area

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 4:10 pm
by L0771
Kexík wrote:Hmm thanks, about that workaround, you mean like, when prototypes are loaded i will save their base_area for example like myTable[prototype.name] = prototype.liquid_box.base_area (with all necessary checks of course), but where can i do it? Do you have any example or link where is mentioned how to do it?
What drs9999 sais is.......
improvised

Code: Select all

for k,tank pairs(data.raw["storage-tank"]) do
	data:extend(
	{
		{
		type = "item",
		name = "fluid-"..tank.name,
		icon = "__mod__/graphics/generic.png",
		flags = {"goes-to-main-inventory"},
		fuel_value = v.fluid_box.base_area.."J",
		subgroup = "a",
		order = "a",
		stack_size = 1
		},
	}
	)
end
and game.itemprototypes["fluid-storage-tank"].fuelvalue can get the fluid_box...
or ["entity"].prototype.fuelvalue

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 4:24 pm
by Kexík
Oh cool, thanks.

One question I have to use this in data.lua? Or can i use it in control.lua because i though that data is not modifiable in scripts?

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 4:31 pm
by drs9999
Dammit I was to slow :D
Yes I meant what L0771 said.
Kexík wrote:Oh cool, thanks.
One question I have to use this in data.lua? Or can i use it in control.lua because i though that data is not modifiable in scripts?
Yes, you have to create the items in data.lua. It's like you said prototypes are read-only once loading is done.

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 4:42 pm
by L0771
drs9999 wrote:Yes, you have to create the items in data.lua. It's like you said prototypes are read-only once loading is done.
I hate this, i have like 1300 items and 400 entities for this... with only an mining-tool.speed editable i can save above 300 items :cry:

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 4:43 pm
by Kexík
Thanks,
i will use it, but i guess it will not work with others mod like i hoped. When my mod will be loaded before another, i will have no other oprion then use magic number because meta-item will not exist

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 4:45 pm
by L0771
Kexík wrote:Thanks,
i will use it, but i guess it will not work with others mod like i hoped. When my mod will be loaded before another, i will have no other oprion then use magic number because meta-item will not exist
Can add dependencies like scrapmod, and i think don't need the version
+

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 4:54 pm
by n9103
A couple of Bob's mods also have this optional dependencies setup, changing the recipes and such if the optional mods are active. Bob's Assemblers is the one I have personal experience with.

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 4:57 pm
by Kexík
Oh, if dependenci have ? before name it mean i dont have to have it, but if i have it will load it before my?

Thank you guys, a learned a lot and fixed more problems than only the one mention at first post :]

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 4:59 pm
by L0771
Kexík wrote:Oh, if dependenci have ? before name it mean i dont have to have it, but if i have it will load it before my?
yep, is optional dependency.

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 5:11 pm
by n9103
That's what we're here for :)
Glad you've solved that problem.

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 5:25 pm
by Kexík
Ok last question (i hope) when making meta-items, can i use some group that will not be visible when seting conditions from smart-inserters ?

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 5:41 pm
by L0771

Code: Select all

data:extend(
{
    {
    type = "item-group",
    name = "nombre",
    order = "a",
    inventory_order = "z",
    icon="__icon-mod__/icons/icon/reicon/iconicon/icon.png"
    }
}
)
and set this name in subgroup.
in factorio by default only can see what can you craft, if this group have no one recipe, you can't see. Only can see by smart inserter and logistic slots.


* All my names are generic

Re: Storage tank max size info

Posted: Fri Dec 19, 2014 5:43 pm
by Kexík
Oh, ok thx