Boundless Creative mode Lua scripting documentation

I am getting this with inventory example.
bad argument #1 to 'ipairs' (table expected, got userdata)

I am able access inventory by elements, for example way to get capacity.
containerEntity.inventory[1]:capacity()
But I can’t output inventory name properly. I don’t know is this way proper to do but example wasn’t enough for me.

Here is way I did copy player inventory to barrel that was also generated.

--From Daves Arena
function setBlock(x, y, z, blockType, color, meta)
    if meta == nil then
        meta = 0;
    end
    local p = boundless.wrap(boundless.UnwrappedBlockCoord(x, y, z))
    local c = boundless.ChunkCoord(p)
    boundless.loadChunkAnd8Neighbours(c, function (chunks)
        local v = boundless.getBlockValues(p)
        v.blockType = blockType
        v.blockMeta = meta
        v.blockColorIndex = color
        boundless.setBlockValues(p, v)
    end)
end

--
--https://stackoverflow.com/a/26777901
function round(x)
    return x>=0 and math.floor(x+0.5) or math.ceil(x-0.5)
end
--
function inventoryContainer() 
    for c in boundless.connections() do
        local e = boundless.getEntity( c.id );
        local containerType = boundless.blockTypes.STORAGE_WOOD_STYLISH;
        -- containerType = boundless.blockTypes.CONTAINER_STORAGE_BASE;    --stone storage block
        -- containerType = boundless.blockTypes.CONTAINER_STORAGE_SHELF;   --wood shelf
        local signType = boundless.blockTypes.SIGN_METAL_BASE;
        local signColor = 2; -- IRON

        if e then
            local pos = e.position:copy();--:withYOffset(0.5)
            local y = math.floor(pos.y) + 1;
            local x = math.floor(pos.x);
            local z = math.floor(pos.z);

            local sinr = round( math.sin( e.facing )); --NS
            local cosr = round( math.cos( e.facing )); --WE
            
            z = z + 2*sinr;
            x = x + 2*cosr;
            
            setBlock( x, y, z, containerType, math.random(255) );
            setBlock( x, y, z-1, signType, signColor, 6 );   --placing sign to north side and setting it on south wall
            -- sign meta 
            --1 = west
            --2 = east
            --3 = ground
            --4 = ceiling
            --5 = north
            --6 = south
            
            local containerBlockCoord = boundless.wrap(boundless.UnwrappedBlockCoord(x, y, z))
            local containerEntity = boundless.getEntity( containerBlockCoord );
            
            if( containerEntity ~= nil ) then
                local containerCapacity = containerEntity.inventory[1]:capacity();
                for i=1, containerCapacity do
                    if( e.inventory[1][i] ~= nil ) then
                        local copyI = e.inventory[1][i]:copy();
                        containerEntity.inventory[1][i] = copyI;
                    end
                end
            else
                print( "Error with container entity!" )
            end
            
            local signEntity = boundless.getEntity( boundless.wrap(boundless.UnwrappedBlockCoord(x, y, z-1)))
            if( signEntity ~= nil ) then
                signEntity.text = c.username;
                signEntity.additionalText = os.utctime();
            end
        end
    end
end

I did start playing with inventory because of @Nitloc did mention that creative won’t allow spawning undo and lattice chisels from menu. At least with deep-copying items forged items can be duplicated :slight_smile:

Below way to copy just 1st slot from inventory which is probably more useful for forged items.

for c in boundless.connections() do
    local e = boundless.getEntity( c.id );
    if e then
        if( e.inventory[1][1] ~= nil ) then
            local copyI = e.inventory[1][1]:copy();
            boundless.spawnItem( copyI, e.position )
        end
    end
end
1 Like