Jump to content

RussNash37

Member
  • Posts

    1
  • Joined

  • Last visited

Reputation Activity

  1. Like
    RussNash37 reacted to NQ-Deckard in LUA getItemsList() and how it works ?   
    Hello HomerGAdams!

    There are actually 3 steps to the process of retrieving and processing the container information

    The container content is not loaded by default, first you will need to request the content through:
    container.acquireStorage() This is limited to 10 calls every 5 minutes, if you go over that it will trigger a cooldown.
     
    This call is not immediate and takes a (short) time to arrive.
    Once that data arrives and is available to use an event is triggered on the container slot called 
    storageAcquired() You can simply set a filter on the container unit and it will be triggered everytime container.acquireStorage() has successfully returned results.
     
    Inside storageAcquired() you will now likely want to use
    jsonString = container.getItemsList() or alternatively deconstruct the JSON data directly:
    itemList = json.decode(container.getItemsList())  
    The item list will then be a numbered table containing the item slots in the container, and each entry will have the follow fields available to it:
    name, quantity, unitVolume, unitMass, type, class
     
    If you want a practical example to look at you can copy the following and use "Paste Lua Configuration from Clipboard" onto a programming board.
    {"slots":{"0":{"name":"container","type":{"events":[],"methods":[]}},"1":{"name":"screen","type":{"events":[],"methods":[]}},"2":{"name":"slot3","type":{"events":[],"methods":[]}},"3":{"name":"slot4","type":{"events":[],"methods":[]}},"4":{"name":"slot5","type":{"events":[],"methods":[]}},"5":{"name":"slot6","type":{"events":[],"methods":[]}},"6":{"name":"slot7","type":{"events":[],"methods":[]}},"7":{"name":"slot8","type":{"events":[],"methods":[]}},"8":{"name":"slot9","type":{"events":[],"methods":[]}},"9":{"name":"slot10","type":{"events":[],"methods":[]}},"-1":{"name":"unit","type":{"events":[],"methods":[]}},"-2":{"name":"system","type":{"events":[],"methods":[]}},"-3":{"name":"library","type":{"events":[],"methods":[]}}},"handlers":[{"code":"-- Event was fired so we now have the container content.\nitems = json.decode(container.getItemsList())\n\n-- Lets make an HTML table to display all the data.\nlocal html = [[\n<div class=\"bootstrap\" width=\"1vw\" height=\"1vh\">\n\t<table>\n\t\t<tr>\n\t\t\t<th>name</th>\n\t\t\t<th>quantity</th>\n\t\t\t<th>unitVolume</th>\n\t\t\t<th>unitMass</th>\n\t\t\t<th>type</th>\n\t\t\t<th>class</th>\n\t\t</tr>\n]] \n\n-- iterate over the container data and add the items to the table\nfor entry,itemData in ipairs(items) do\n html = html..[[\n\t\t<tr>\n\t\t\t<td>]]..itemData[\"name\"]..[[</td>\n\t\t\t<td>]]..itemData[\"quantity\"]..[[</td>\n\t\t\t<td>]]..itemData[\"unitVolume\"]..[[</td>\n\t\t\t<td>]]..itemData[\"unitMass\"]..[[</td>\n\t\t\t<td>]]..itemData[\"type\"]..[[</td>\n\t\t\t<td>]]..itemData[\"class\"]..[[</td>\n\t\t</tr>\n ]]\nend\n\n-- End the table\nhtml = html..[[\n\t</table>\n</div>\n]]\n\n-- Write to the screen\nscreen.setHTML(html)","filter":{"args":[],"signature":"storageAcquired()","slotKey":"0"},"key":"0"},{"code":"-- When the board starts up let the player know the data is being retrieved (This could be quick or slow)\nscreen.setHTML([[<div class=\"bootstrap\" style=\"font-size:5vw; \">Retrieving container data</div>]])\n\n-- Lets prepare an empty table for the data to go into\n-- This prevents other functions from receiving null until the data is retrieved.\nitems = {} \n\n-- Start a request for the container data \n-- this will trigger an event in the container slot when completed\n-- We can only do this 10 times per 5 minutes, or a cooldown will be triggered.\ncontainer.acquireStorage()","filter":{"args":[],"signature":"start()","slotKey":"-1"},"key":"1"}],"methods":[],"events":[]}  
     
    I hope this helps answer your question, if not please do let me know  
     
    NQ-Deckard
×
×
  • Create New...