How to Use Optional Parameters

Place to get help with not working mods / modding interface.
DARKHAWX
Burner Inserter
Burner Inserter
Posts: 6
Joined: Thu May 10, 2018 10:19 am
Contact:

How to Use Optional Parameters

Post by DARKHAWX »

According to the docs I should be able to call LuaLogisticNetwork.get_item_count(item, member). Item and member are both optional string parameters. I only want to pass a member parameter to the function (i.e. I want a total item count but only from storage chests). I don't know how to do this. If I don't pass the item parameter it thinks the member parameter is the item parameter (because im only passing one parameter) and tries to get me an item count for "storage", which isn't a valid item and so it returns an error. If I pass an empty string, a nil value or anything that isn't a valid item it returns an error.

How can I run this function but only pass the member parameter?
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: How to Use Optional Parameters

Post by eradicator »

You can not. For all functions with positional arguments, all arguments that come before the one you want are mandatory, even if the individual arguments would be optional. I.e. for your example there are only three possible calls:

LuaLogisticNetwork.get_item_count()
LuaLogisticNetwork.get_item_count(item)
LuaLogisticNetwork.get_item_count(item, member)

You could try requesting that "item" optionally takes a list of names instead i guess.
Post Reply

Return to “Modding help”