Tutorial world.containerItems()

Discussion in 'Starbound Modding' started by The | Suit, Feb 19, 2017.

Tags:
  1. The | Suit

    The | Suit Agent S. Forum Moderator

    Since it took me a while to decipher what is going on and the Lua docs for it was pretty much too vague to be helpful I am writing this guide.

    world.containerItems(entity.id()) - is a Lua function that lists all items inside a container when you give it an entity.id to check.
    If the object is not a container it returns nil.



    Primary Table[Slot Table 1, Slot Table 2 , Slot Table 3]

    Slot Table[name]
    Slot Table[count]
    Slot Table[parameter]

    Parameter["various parameter string keys"]



    Primary Table
    The output is primary.table = world.containerItems(entity.id())
    table position : slot position
    slot number: secondary table.

    Example;
    1 : secondary table

    where 1 is the first slot ( not a stringed key ) - and it gives you another table.


    Secondary Table
    is composed of stringed keys, "name", "count", "parameters"
    name and count will give you the respective values of that item in the slot in the primary table
    parameters = tertiary table

    Tertiary table
    Composed of stringed keys.


    To give you an example code with log.


    Code:
    function vProc()
      sb.logInfo("Processing")
      sb.logInfo(aa)
      sb.logInfo(tostring(ab).. " main table")
        for i,v in pairs(world.containerItems(entity.id())) do
          sb.logInfo(tostring(ab[1]).. " Test")
          sb.logInfo(i .." Loop 1")
          sb.logInfo(tostring(v).. " Table 1")
          cstate02 = v
          vProc2()
        end
       sliq()
    end
    
    function vProc2()
      sb.logInfo("vProc2")
      sb.logInfo(tostring(cstate02["name"]).. " name")
      sb.logInfo(tostring(cstate02["count"]).. " count")
      for i,v in pairs(cstate02) do
        sb.logInfo(i.. " Loop 2")
        sb.logInfo(tostring(v).. " table 2")
      end
    end
    
    Code:
    [08:07:29.307] [Info] 14
    [08:07:29.307] [Info] table: 000001E0430FE9C0 main table
    [08:07:29.308] [Info] table: 000001E0430FEAC0 Test
    [08:07:29.308] [Info] 1 Loop 1
    [08:07:29.308] [Info] table: 000001E04377E4C0 Table 1
    [08:07:29.308] [Info] vProc2
    [08:07:29.308] [Info] goldbar name
    [08:07:29.308] [Info] 990 count
    [08:07:29.308] [Info] count Loop 2
    [08:07:29.308] [Info] 990 table 2
    [08:07:29.308] [Info] name Loop 2
    [08:07:29.308] [Info] goldbar table 2
    [08:07:29.308] [Info] parameters Loop 2
    [08:07:29.308] [Info] table: 000001E04377E5C0 table 2
    [08:07:29.308] [Info] table: 000001E0430FEAC0 Test
    [08:07:29.308] [Info] 2 Loop 1
    [08:07:29.308] [Info] table: 000001E04377E640 Table 1
    [08:07:29.309] [Info] vProc2
    [08:07:29.309] [Info] silverbar name
    [08:07:29.309] [Info] 990 count
    [08:07:29.309] [Info] count Loop 2
    [08:07:29.309] [Info] 990 table 2
    [08:07:29.309] [Info] name Loop 2
    [08:07:29.309] [Info] silverbar table 2
    [08:07:29.309] [Info] parameters Loop 2
    [08:07:29.309] [Info] table: 000001E04377E740 table 2
    

    Hopefully this saves some one else using this function some time.
     
    Last edited: Feb 19, 2017

Share This Page