353 posts
Location
Orewa, New Zealand
Posted 18 May 2014 - 05:07 AM
Hi Again, trying to make a program that emits a signal when the turbine is full of RF, this part works…. BUT when i input the while true do, it spammed the print command i have in there, how do i alter the code to stop this, i basically want it to check if the turbine is full or not and tell me, but keep checking.
local reactor = peripheral.wrap("back") --side of turbine
turb = "0" --settting variable to 0s
while true do --the loop
turb = reactor.getEnergyStored() --Gets the internal storage from the turbine
sleep(0)
if turb == 1000000 then
print("OMG Its FULL!")
rs.setOutput("bottom", false)
end
if turb < 1000000 then
term.clear() --clears the screen to stop it from overwriting
print ("Uh Oh, Its Running Out") --displays the message to me
rs.setOutput("bottom", true) --turns on the reactor
end
end --while end
3057 posts
Location
United States of America
Posted 18 May 2014 - 03:40 PM
I'd sleep for more than 0 seconds for one thing.
Add term.setCursorPos(1, 1) after term.clear() to reset the position it is printing at.
197 posts
Location
Czech Republic
Posted 18 May 2014 - 04:35 PM
Here you go
local reactor = peripheral.wrap("back") --side of turbine
turb = 0 --#settting variable to 0s - set to NUMBER not STRING
while true do --the loop
term.clear()
term.setCursorPos(1,1) --#clear the screen HERE
turb = reactor.getEnergyStored() --#Gets the internal storage from the turbine
sleep(0.5) --#check for update every 0.5 second
if turb == 1000000 then
print("OMG Its FULL!")
rs.setOutput("bottom", false)
end
if turb < 1000000 then
--#dont clear the screen here
print ("Uh Oh, Its Running Out") --#displays the message to me
rs.setOutput("bottom", true) --#turns on the reactor
end
end --while end
9 posts
Posted 19 May 2014 - 02:44 AM
Started taking a stab at this before reading comments because I'm an idiot, oh well you might learn a thing or two anyway
local reactor = peripheral.wrap("back") --#side of turbine
turb = 0 --# assigning value to avoid variable type errors (int vs string etc?) idk
while true do --# the main loop
sleep(10) --# Waits 10 seconds before doing anything
turb = reactor.getEnergyStored() --# Gets the internal storage from the turbine
term.clear() --# Clears anything currently on screen for ya, yer welcome
term.setCursorPos(1, 1) --# print function adjusts the cursor position, so we must re-adjust to 1
--# (you could use write("") instead, which doesnt change the cursor position)
if turb ~= 1000000 then
print("Uh oh, it's not full")
redstone.setOutput("bottom", true)
print("Reactor engaged!")
break --# jump outta dis if statement
else
print("Yup, topped off!")
redstone.setOutput("bottom", false)
break --# well, I mean, if we made it here were ending here but why not
end --# ends if statement
end --# ends the while loop
Made it more readable with those pound signs
Edited on 19 May 2014 - 12:47 AM
197 posts
Location
Czech Republic
Posted 19 May 2014 - 06:59 AM
Started taking a stab at this before reading comments because I'm an idiot, oh well you might learn a thing or two anyway
local reactor = peripheral.wrap("back") --#side of turbine
turb = 0 --# assigning value to avoid variable type errors (int vs string etc?) idk
while true do --# the main loop
sleep(10) --# Waits 10 seconds before doing anything
turb = reactor.getEnergyStored() --# Gets the internal storage from the turbine
term.clear() --# Clears anything currently on screen for ya, yer welcome
term.setCursorPos(1, 1) --# print function adjusts the cursor position, so we must re-adjust to 1
--# (you could use write("") instead, which doesnt change the cursor position)
if turb ~= 1000000 then
print("Uh oh, it's not full")
redstone.setOutput("bottom", true)
print("Reactor engaged!")
break --# jump outta dis if statement
else
print("Yup, topped off!")
redstone.setOutput("bottom", false)
break --# well, I mean, if we made it here were ending here but why not
end --# ends if statement
end --# ends the while loop
Made it more readable with those pound signs
Wrong. Break exits the while loop. Also, write function does adjust the cursor position, but does not affect y axis (no EOF character)