Jump to content




Until loop - reactor control


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

#1 Dustmuz

  • Members
  • 174 posts
  • LocationDenmark

Posted 09 March 2015 - 11:56 PM

im working on a new reactor controller, just for the sake of having made like a few to many :P hehe

this time i want the reactor to turn on the reactor if the storage is below 200K RF

local mon = peripheral.wrap("monitor_1")
local bank = peripheral.wrap("tile_blockcapacitorbank_name_0")
local rea = peripheral.wrap("bottom")

local function pos(x,y)
  mon.setCursorPos(x,y)
end

pos(1,1)
mon.write("Vibrant Capacitor bank")

while true do
  local banken = bank.getEnergyStored()
  pos(1,2)
  mon.clearLine()
  if banken >= 1000000 then
    local enermill = math.floor((banken*16)/1000000)
    mon.write("Energy Stored:"..enermill.." Million RF")
  elseif banken <= 1000000 then
    local enerthou = math.floor((banken*16)/1000)
    mon.write("Energy Stored:"..enerthou.." Thousand RF")
    if enerthou <= 200 then
      rea.setActive(true)
    else
      rea.setActive(false)
    end
  end

  sleep(2)

thats the code i use atm for controlling the power atm

the code i want to change is this
    if enerthou <= 200 then
      rea.setActive(true)
    else
      rea.setActive(false)
    end

to somethin like a until statement..
and thats where i get lost :D hehe, its pretty late, so im sorry if i didnt notice something obvious :)

i looked up the repeat loop, but wouldnt it just lock the entire program to that loop, until the power got above a certain point??
if that is true, then i will just put it in a function on its own, and use the parallel.waitForAny

so what i am asking for i the end, is the means to make a "until loop" withing the current code i have :)

#2 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

Posted 10 March 2015 - 12:46 AM

Are you saying you want to add a loop to the script there? I'm not sure why you'd do that... :wacko:

For what it's worth, I'd turn this:

    if enerthou <= 200 then
      rea.setActive(true)
    else
      rea.setActive(false)
    end

... into this:

    rea.setActive(enerthou <= 200)


#3 Dustmuz

  • Members
  • 174 posts
  • LocationDenmark

Posted 10 March 2015 - 09:28 AM

View PostBomb Bloke, on 10 March 2015 - 12:46 AM, said:

Are you saying you want to add a loop to the script there? I'm not sure why you'd do that... :wacko:

For what it's worth, I'd turn this:

	if enerthou <= 200 then
	  rea.setActive(true)
	else
	  rea.setActive(false)
	end

... into this:

	rea.setActive(enerthou <= 200)

yeps.. it was what i was trying to do :D

i derped a bit as i was tired, as the answer was actually staring at me :D hehe..
when i read your answer this morning (its 10am here)
i knew how i should do it :D hehe.. so i ended up with this :D

[code
if enerthou <= 200 then
rea.setActive(true)
elseif enermill >= 350 then
rea.setActive(false)
end
[/code]

it actually works :D





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users