Read From a Delimited String of Values

local _object = {}

local _objects = 0

function __O() _objects = _objects + 1 return _objects end

-- bush, house, rock, tree
-- grid, reference, desc, xyz offset

_object[__O()] = "coin|a Manticoin.|(3,3,200)|"

_object[__O()] = "companion|An Aperture Science weighted companion cube.|(3,3,200)|"

_object[__O()] = "health1|a bandage.|(3,3,200)|"

_object[__O()] = "health2|a healthpack.|(3,3,200)|"

_object[__O()] = "house|a simple house.|(3,3,200)|"            -- NOT DONE!

_object[__O()] = "plant1|a simple bush.|(3,3,200)|"

_object[__O()] = "rock|a simple rock.|(3,3,200)|"

_object[__O()] = "tree1|a birch tree.|(3,3,200)|"

_object[__O()] = "tree2|a bigger birch tree.|(3,3,200)|"

_object[__O()] = "tree3|a small redwood tree.|(3,3,200)|"

_object[__O()] = "tree stump|a large oak tree stump|(3,3,200)|"



_object._count = _objects


function _object._getObjectList()
    local _test = "Here's some test text."
    local _list = tostring(_objects).." objects:\n"
    local __ref     = nil
    local __desc     = nil
    local __ofs     = nil
    local _line        = nil
    local a            = 1
    local _split    = {}
    for b=1,_objects do
        _line = _object[b]
        a = 1    
        _split = {}
        for i in string.gmatch(_line, "([^|]*)|") do -- | delimiter
            _split[a] = i -- get our 3 values: split[1-3]
            a = a + 1
        end
        --ref, desc, ofs
        --print("ITERATION: ",b)
        __ref     = _split[1]
        __desc     = _split[2]
        __ofs     = _split[3]
        _list     = _list..__ref.." - "..__desc.."\n"
    end    
    
    --return "Count: "..tostring(_object._count) -- all tests work!
    --return _list.._test.." - ".._test.."\n"
    --return _cmd[2]
    return _list
end




return _object

Latest Posts