Hi, I'm trying to assign multiple turbines using tables (First time using tables by the way)
and I'm having problems Ive been searching google and forum but i cant seem to find the help i need
Could anyone shed some light on what I'm doing wrong?
http://pastebin.com/sKJ8p82n
thanks,
Sky
Having problems with tables
Started by SkyDevil_, Aug 01 2015 08:08 PM
7 replies to this topic
#1
Posted 01 August 2015 - 08:08 PM
#2
Posted 01 August 2015 - 08:26 PM
{peripheral.find} returns a table of already wrapped peripherals, so your for loop is unnessary/wrong.
You will have to loop though that table when you want to call any functions though. For convenience you can create functions that do the looping for you:
You will have to loop though that table when you want to call any functions though. For convenience you can create functions that do the looping for you:
local reactors = {peripheral.find ("whatever")}
local function setActive (active)
for i, reactor in ipairs (t)
reactor.setActive (active)
end
end
#3
Posted 01 August 2015 - 09:40 PM
Ok thanks how would i set each Turbine a name IE if it was done normally it would be.
T1 = peripheral.wrap("BigReactors-Turbine_0")
#5
Posted 01 August 2015 - 10:26 PM
I read so much about tables but i can seem to grasp it fully
Guess i will keep trying lol thanks for the help all
Guess i will keep trying lol thanks for the help all
#6
Posted 02 August 2015 - 03:48 AM
Hi, Another question
I am currently trying to add the total RF per a tick generated for all of the turbines im able to call the value pretty easy but i need to find a way to add the value together for all 10 turbines so i get a total value.
the only way i know to do this is:
Is there a more efficient way?
Edit is the also a way to remove the decimal at the end of the Total?
I am currently trying to add the total RF per a tick generated for all of the turbines im able to call the value pretty easy but i need to find a way to add the value together for all 10 turbines so i get a total value.
the only way i know to do this is:
Total = T[1].getEnergyProducedLastTick() + T[2]getEnergyProducedLastTick() + T[3].......
Is there a more efficient way?
Edit is the also a way to remove the decimal at the end of the Total?
Edited by SkyDevil_, 02 August 2015 - 03:48 AM.
#7
Posted 02 August 2015 - 04:25 AM
for i, turbine in pairs(turbines) do Total = Total + T[i].getEnergyProducedLastTick() endTo get rid of the decimal, you can round the total using either math.floor() or math.ceil().
Bomb Bloke has a better loop and more info on the roudning below
Edited by grand_mind1, 02 August 2015 - 04:29 AM.
#8
Posted 02 August 2015 - 04:26 AM
When it comes to dealing with multiple entries in a table, usually the answer is "for loops".
Eg:
If you're getting a ".0" when mon.write()'ing numbers, tostring() them. If you wish to round them down, math.floor() them.
Eg:
local Total = 0 for i = 1, #T do Total = Total + T[i].getEnergyProducedLastTick() end
If you're getting a ".0" when mon.write()'ing numbers, tostring() them. If you wish to round them down, math.floor() them.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











