Well, function would be 100% percent accurate if you add the relevant checks.
Also, where did you get that 'energy_usage'? Neither current nor next version expose that to runtime.
get a list of valid inventories for an entity
Re: get a list of valid inventories for an entity
I do mods. Modding wiki is friend, it teaches how to mod. Api docs is friend too...
I also update mods, some of them even work.
Recently I did a mod tutorial.
I also update mods, some of them even work.
Recently I did a mod tutorial.
Re: get a list of valid inventories for an entity
I filed a bug report alongside this request. Trying to access a nonexistent inventory index is currently a crash condition rather than returning nil. Someone on IRC pointed me towards pcall() to catch the error in lua and discard it, but that's really bad practice. Fortunately the bug report is already marked fixe din 0.13, so iterating through all indices and checking for nil is a viable approach next version.Sean Mirrsen wrote:Depending on what you're trying to do, you might make do with checking via can_insert, or just running through the whole table of inventory indices and seeing what returns nil.
I do not trust that anyone, including myself, is able to list every one of the relevant checks. Together a few of us can probably get 99%, missing some corner cases that will show up in random situations with weird mods.Adil wrote:Well, function would be 100% percent accurate if you add the relevant checks.
Just copied it from a post higher in this thread. This further proves my point. Coming up with the list of "relevant checks" is non-trivial.Adil wrote:Also, where did you get that 'energy_usage'? Neither current nor next version expose that to runtime.
Re: get a list of valid inventories for an entity
That's why this thread is in Modding interface requests.Adil wrote:Also, where did you get that 'energy_usage'? Neither current nor next version expose that to runtime.
Re: get a list of valid inventories for an entity
+1 for this request. Don't just throw an error if you're trying to access an inventory index that doesnt exist.
Either add a function to check if the inventory exists, or just return nil perhaps?
It is VERY bad practice that the end users have to determine based on the type of the entity what inventories it supports.
100% unmaintainable.
Either add a function to check if the inventory exists, or just return nil perhaps?
It is VERY bad practice that the end users have to determine based on the type of the entity what inventories it supports.
100% unmaintainable.
My mod: "Auto Deploy Destroyers" (follower robots) viewtopic.php?f=97&t=24545
Re: get a list of valid inventories for an entity
Already confirmed in the bug report forum that get_inventory() will return nil instead of error in 0.13slindenau wrote:+1 for this request. Don't just throw an error if you're trying to access an inventory index that doesnt exist.
Either add a function to check if the inventory exists, or just return nil perhaps?
It is VERY bad practice that the end users have to determine based on the type of the entity what inventories it supports.
100% unmaintainable.
Re: get a list of valid inventories for an entity
Indeed. It made no sense to throw an error since multiple entities might have or won't have an inventory and there was no way to know if it did before calling "get".sparr wrote:Already confirmed in the bug report forum that get_inventory() will return nil instead of error in 0.13slindenau wrote:+1 for this request. Don't just throw an error if you're trying to access an inventory index that doesnt exist.
Either add a function to check if the inventory exists, or just return nil perhaps?
It is VERY bad practice that the end users have to determine based on the type of the entity what inventories it supports.
100% unmaintainable.
if anyone comes across other methods that throw errors when it doesn't make sense feel free to make bug reports about them. Specifically something is meant to throw an error when it's easily possible to tell if you should be calling that method to begin with. Something like trying to set a recipe on a rock for instance would be an error - you should only ever be calling that on an assembling machine type entity. Trying to get the electric energy of an entity however shouldn't generate an error because there's no good way to tell if an entity actually has electric power without just calling the get property.
If you want to get ahold of me I'm almost always on Discord.