function updateText()
os.sleep(1)
term.clear()
door1()
door1scan()
updateText()
end
function door1()
if doorStat1 == true then
term.setCursorPos(1,2)
term.clearLine()
term.setTextColor(colors.green)
term.write"Door 1 is OPEN."
else
term.setCursorPos(1,2)
term.clearLine()
term.setTextColor(colors.red)
term.write"Door 1 is CLOSED"
end
end
function door1scan()
local event, scancode = os.pullEvent("key")
if scancode == 57 and doorStat1 == false then
doorStat1 = true
end
if scancode == 57 and doorStat1 == true then
doorStat1 = not doorStat1
end
end
updateText()
Security/shield Program Problem, No Error. Help Please.
Started by popdog15, Jan 24 2013 02:34 PM
2 replies to this topic
#1
Posted 24 January 2013 - 02:34 PM
Well, this is a security/door program. When the user presses space it is meant to toggle the state from open to closed, or vice-versa. Anyone know why this isn't doing as intended?
#2
Posted 24 January 2013 - 02:38 PM
it is because you have the structure of the program the wrong way around... a function should be declared BEFORE it is used...
EDIT: Also your door1scan() can be changed to this

EDIT #2: Also you don't seem to have any loop in there, meaning that the program will just terminate when you press space... I suggest adding an infinite while loop in there...
Something like this would work well
EDIT: Also your door1scan() can be changed to this
function door1scan()
local event, scancode = os.pullEvent("key")
if scancode == 57 then
doorStat1 = not doorStat1
end
end
you had extra redundant logic in there EDIT #2: Also you don't seem to have any loop in there, meaning that the program will just terminate when you press space... I suggest adding an infinite while loop in there...
Something like this would work well
Spoiler
Edited by TheOriginalBIT, 24 January 2013 - 02:47 PM.
#3
Posted 24 January 2013 - 03:14 PM
Thanks!
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











