This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
camadas's profile picture

return 2 values, assign them to variables

Started by camadas, 07 January 2014 - 02:33 PM
camadas #1
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?
Lyqyd #2
Posted 07 January 2014 - 03:39 PM
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
camadas #3
Posted 07 January 2014 - 03:52 PM
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

Belive it or not, I did use google and such for it :P/>, I never create a new topic just for the sake of it :D/>.

And yes I have done that, I have changed the code on the read of the redstone energy cell, so I only need to change the statement on the for, and the rest It will get it automatic:


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

Now I'm returning the mj on the energy cells and the total that it can store, now what I was asking is how I can access to it :D/>.

I have this function to it


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

Thanks :D/>
Edited on 07 January 2014 - 02:53 PM
Lyqyd #4
Posted 07 January 2014 - 04:02 PM
The same general way.


local first, second = func()
camadas #5
Posted 07 January 2014 - 04:07 PM
The same general way.


local first, second = func()

Thanks :D/> and sorry again for this "basic" questions