Jump to content




return 2 values, assign them to variables

help

  • You cannot reply to this topic
4 replies to this topic

#1 camadas

  • Members
  • 16 posts

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?

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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


#3 camadas

  • Members
  • 16 posts

Posted 07 January 2014 - 03:52 PM

View PostLyqyd, on 07 January 2014 - 03:39 PM, said:

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 by camadas, 07 January 2014 - 03:53 PM.


#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 07 January 2014 - 04:02 PM

The same general way.

local first, second = func()


#5 camadas

  • Members
  • 16 posts

Posted 07 January 2014 - 04:07 PM

View PostLyqyd, on 07 January 2014 - 04:02 PM, said:

The same general way.

local first, second = func()

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users