This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
tipsyMJT's profile picture

Beginner in need of help

Started by tipsyMJT, 12 July 2012 - 04:44 AM
tipsyMJT #1
Posted 12 July 2012 - 06:44 AM
i just started using this mod and i need some help because i dont fully understand what the coding is doing. I have a door to be opened on startup when i type "'open" but i dont want it to close until i enter the computer again and type "close". with my extremely basic understanding of how these things work i came up with this on startup.

function pass()
t = io.read()
if t == "open" then
redstone.setOutput("back" , true)
pass()
if t == "close" then
redstone.setOutput("back" , false)
pass()
else
pass()
end
end
pass()

when i startup the system it say bios:206: [string "startup"]:7: unfinished string
if you correct my code please tell me what i did wrong and at least try to teach me.
Jarle212 #2
Posted 12 July 2012 - 10:34 AM
You shuldn't call your function inside the function

Try this, and use ctrl + t to terminate



 
function pass()
local p = read("*")
if p == "open" then
return 1
end
if p == "close" then
return 2
end
end

while true do
com = pass()
if com == 1 then
[color=#282828][font=helvetica, arial, sans-serif]redstone.setOutput("back" , true)[/font][/color]
end
if com == 2 then
[color=#282828][font=helvetica, arial, sans-serif]redstone.setOutput("back" , false)[/font][/color]
end
end


Jarle212 #3
Posted 12 July 2012 - 10:36 AM
can't see any wrong with you string thought on line 7
jay5476 #4
Posted 13 July 2012 - 11:47 AM
try

term.clear()
term.setCursorPos(1,1)
while true do
print("Door control, do you want to open or close")
t = io.read()
if t == "open" then
rs.setOutput("back",true)
print("Door Opening")
sleep(1)
term.clear()
term.setCursorPos(1,1)
end
if t == "close" then
rs.setOutput("back",false)
print("Door Closing")
sleep(1)
term.clear()
term.setCursorPos(1,1)
end
end
this will also put some text on the screen :)/>/> Works 100% ctrl+T to terminate