Posted 02 November 2012 - 04:38 AM
I am making a computer powered blaze farm. This code is supposed to create a GUI for controlling the farm. This is one of my first attempts at coding so I am confused at why this won't work. The menu doesn't update like i expected it to. Also, turning on and off the farm doesnt work from the menu. I spent many hours trying to figure out what was wrong, but i still couln't figure it out so now i am asking you.
local cursorPos = 0 –var used to keep track of cursor
local status –whether or not farm is on
local waterFlow –whether or not water is flowing into chamber
–toggles water in blaze chamber to kill blazes or push drops
function switchWater()
rs.setBundledOutput("back", 16)
sleep(1)
rs.setBundledOutput("back", 0)
end
–crushes blazes to bring them down to 1 heart
function crush()
rs.setBundledOutput("back", 4)
sleep(1.5)
rs.setBundledOutput("back", 5)
sleep(9.5)
rs.setBundledOutput("back", 4)
sleep(10)
rs.setBundledOutput("back", 0)
end
–raises spawner with frames to stop spawning
function raiseSpawner()
for i = 1, 3 do
rs.setBundledOutput("back", 2)
sleep(.4)
rs.setBundledOutput("back", 0)
sleep(.4)
end
end
–lowers spawner with frames to begin spawning
function lowerSpawner()
for i = 1, 3 do
rs.setBundledOutput("back", 8)
sleep(.4)
rs.setBundledOutput("back", 0)
sleep(.4)
end
end
–function that is executed when i press enter on menu
function enter()
if cursorPos == 0 and status == "off" then
lowerSpawner()
elseif cursorPos == 0 and status == "on" then
raiseSpawner()
elseif cursorPos == 1 then
switchWater()
elseif cursorPos == 2 then
crush()
elseif cursorPos == 3 then
os.shutdown()
end
end
–checks if farm and water is on to relay to the menu
function checkStatus()
if rs.getBundledInput("bottom", 1 or 3) == false then
status = "On"
elseif rs.getBundledInput("bottom", 0 or 2) then
status = "Off"
end
–when you turn on/off the farm, it activates an rsnor latch
–which goes into bottom of the computer as a white line(RP2)
if rs.getBundledInput("bottom", 1 or 3) == false then
waterFlow = "On"
elseif rs.getBundledInput("bottom", 0 or 2) then
waterFlow = "Off"
–the line of redstone going to pistons to control water feed –into bottom of computer as an orange line
end
end
– write status on the menu
function writeStatus()
checkStatus()
term.clear()
term.setCursorPos(1, 1)
print("Blaze farm control")
term.setCursorPos(4, 4)
print("Blaze Farm Status: ".. status)
term.setCursorPos(4, 6)
print("Water Flow: ".. waterFlow)
term.setCursorPos(4, 8)
print("Crush!")
term.setCursorPos(4, 10)
print("Exit")
term.setCursorPos(3, (cursorPos + 2) * 2)
print(">")
–term.setCursorPos(4, 13)
–print(cursorPos)
end
writeStatus()
while true do
event, param1 = os.pullEvent()
if event == "key" and param1 == 200 then
cursorPos = cursorPos - 1
writeStatus()
elseif event == "key" and param1 == 208 then
cursorPos = cursorPos + 1
writeStatus()
elseif event == "key" and param1 == 28 then
enter()
writeStatus()
end
end
local cursorPos = 0 –var used to keep track of cursor
local status –whether or not farm is on
local waterFlow –whether or not water is flowing into chamber
–toggles water in blaze chamber to kill blazes or push drops
function switchWater()
rs.setBundledOutput("back", 16)
sleep(1)
rs.setBundledOutput("back", 0)
end
–crushes blazes to bring them down to 1 heart
function crush()
rs.setBundledOutput("back", 4)
sleep(1.5)
rs.setBundledOutput("back", 5)
sleep(9.5)
rs.setBundledOutput("back", 4)
sleep(10)
rs.setBundledOutput("back", 0)
end
–raises spawner with frames to stop spawning
function raiseSpawner()
for i = 1, 3 do
rs.setBundledOutput("back", 2)
sleep(.4)
rs.setBundledOutput("back", 0)
sleep(.4)
end
end
–lowers spawner with frames to begin spawning
function lowerSpawner()
for i = 1, 3 do
rs.setBundledOutput("back", 8)
sleep(.4)
rs.setBundledOutput("back", 0)
sleep(.4)
end
end
–function that is executed when i press enter on menu
function enter()
if cursorPos == 0 and status == "off" then
lowerSpawner()
elseif cursorPos == 0 and status == "on" then
raiseSpawner()
elseif cursorPos == 1 then
switchWater()
elseif cursorPos == 2 then
crush()
elseif cursorPos == 3 then
os.shutdown()
end
end
–checks if farm and water is on to relay to the menu
function checkStatus()
if rs.getBundledInput("bottom", 1 or 3) == false then
status = "On"
elseif rs.getBundledInput("bottom", 0 or 2) then
status = "Off"
end
–when you turn on/off the farm, it activates an rsnor latch
–which goes into bottom of the computer as a white line(RP2)
if rs.getBundledInput("bottom", 1 or 3) == false then
waterFlow = "On"
elseif rs.getBundledInput("bottom", 0 or 2) then
waterFlow = "Off"
–the line of redstone going to pistons to control water feed –into bottom of computer as an orange line
end
end
– write status on the menu
function writeStatus()
checkStatus()
term.clear()
term.setCursorPos(1, 1)
print("Blaze farm control")
term.setCursorPos(4, 4)
print("Blaze Farm Status: ".. status)
term.setCursorPos(4, 6)
print("Water Flow: ".. waterFlow)
term.setCursorPos(4, 8)
print("Crush!")
term.setCursorPos(4, 10)
print("Exit")
term.setCursorPos(3, (cursorPos + 2) * 2)
print(">")
–term.setCursorPos(4, 13)
–print(cursorPos)
end
writeStatus()
while true do
event, param1 = os.pullEvent()
if event == "key" and param1 == 200 then
cursorPos = cursorPos - 1
writeStatus()
elseif event == "key" and param1 == 208 then
cursorPos = cursorPos + 1
writeStatus()
elseif event == "key" and param1 == 28 then
enter()
writeStatus()
end
end