Posted 07 January 2014 - 03:33 PM
Hi guys I wonder how i can return 2 values and assign them to a 2 varuables on a new function.
How I can do this?
How I can do this?
return "one", 2, true
This is a pretty basic Lua question. Have you tried using the documentation? You just use multiple comma-separated values in your function's return statement:return "one", 2, true
local e_cell = "redstone_energy_cell_"
function read_energy_cell()
cell_stored = 0
for i=4,15 do
cell = peripheral.wrap(e_cell..i)
cell_stored = cell_stored + cell.getEnergyStored()
end
cell_total = cell.getMaxEnergyStored()
return cell_stored, cell_total
end
function mj()
os.loadAPI("energia/read_mj")
-- want to put cell_stored into one variable and cell_total into another here
os.unloadAPI("energia/read_mj")
end
local first, second = func()
The same general way.local first, second = func()