Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Inventory Items Property Support #214

Open
MerlinofMines opened this issue Feb 10, 2022 · 2 comments
Open

[Feature Request] Inventory Items Property Support #214

MerlinofMines opened this issue Feb 10, 2022 · 2 comments
Labels
documentation Improvements or additions to documentation feature request New feature or request

Comments

@MerlinofMines
Copy link
Owner

MerlinofMines commented Feb 10, 2022

Is your feature request related to a problem? Please describe.
Currently you can't get a sorted list of item names + amounts from either a cargo container, refinery, assembler, etc. You have to know the items up front.

There are a couple challenges to overcome, which I think are doable:

First, there's no good way to access "friendly names" for the inventory items. This is especially true for modded items. So if I were to present the "item name" it would likely be in the form "SubTypeId.TypeId", similar to the Types property. You could then, of course, map those back to whatever names you like using a map of your own creation inside the script.

Second, how to best represent "itemName, quantity" pairs. My instinct says we should use Keyed Values ("itemName" -> amount), and return an ordered collection of them.

The challenge with this, is that currently the "list" construct is supposed to only have 1 key mapped to 1 value, though this is technically not true (it's an artificial constraint). The intention was to create a dictionary like structure that you can look up from. This also can be gotten around though. I propose changing the way lists work such that adding keyed items to a list adds them as entries vs doing a replacement. Only doing an index update directly will do an override of the first keyed entry found (or remove all other entries?). Similarly, retrieving by key would return a list of values if there are more than one entry for the given key, vs just a single entry.

Third, how do you access the "itemName" vs the "amount" for a list of items you are iterating over? If we represent them as keyed values, then we need a way to grab a variable "key" and "value" independently. We could also represent as a list with the first entry being the itemName and the second being the amount. Used keyed variables that would yield:

set myItems to "My Inventory" items
for each item in myItems
  print "Name: " item["name"]
  print "Amount: " + item["amount"]

This change is definitely backwards incompatible, though not in functionality just in structure. I'd be OK making it provided strong call outs during the update that "if you update your script, you may have to adjust it".

Describe the solution you'd like

set myItems to "My Inventory" items
for each item in myItems
  print "Name: " item["name"]
  print "Amount: " + item["amount"]
@MerlinofMines MerlinofMines added documentation Improvements or additions to documentation feature request New feature or request labels Feb 10, 2022
@JordanRL
Copy link

It nearly sounds like you want to use the "list" structure similar to arrays in PHP, which is a flexible combination of a list and dict structure. EC probably doesn't require the same level of flexibility as that structure exactly, but more having a single structure that could be 0-indexed or string-indexed? (PHP arrays can mix the two in the same array, which I don't think is necessary here.)

Alternatively you could use two different structures, though that may be the "nice" thing to do that's impractical due to the optimization/character limitations.

Perhaps such a structure could simplify other things though.

A (perhaps unrelated) additional concern is that when getting a list of items from an inventory of some kind, it may occasionally be useful to return a property describing it's ordering/positioning within the inventory. That's the main concern in my use case that spawned this issue... I wanted the position 0 item name from the first inventory of a refinery.

That would give use three properties available when you get a list of items from an inventory:

  • name: The display/friendly name of the item.
  • amount: The quantity of that item in the inventory.
  • position/order/slot: The inventory position of that item in the given inventory.

An additional consideration may be that position is probably a writable property (strictly speaking from a game perspective), while name and amount are not. Though providing writable access to this property is probably unnecessary, it could enable things like sorts within the inventory via script, or a script that always keeps a particular item at the beginning of a given inventory.

@CorwinMacGregor
Copy link
Contributor

instead of using index notation to refer to a property, what about using dot notation, '.'? a number of other languages do this (though many, such as Lua, do also allow access through index notation as well), and it fits well with its current use of accessing vectors' and colors' components

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation feature request New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants