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

Print doesn't work correctly.

Started by TheOnlyExedra, 13 October 2012 - 08:45 AM
TheOnlyExedra #1
Posted 13 October 2012 - 10:45 AM
Hi everyone,

I'm new to ComputerCraft(not new to Lua scripting though). I've had experience scripting for years using the LÖVE2D engine and ROBLOX. Though I'm new to ComputerCraft and a little confused.
I'm trying to make something print to the screen after the user types in something. I need this for tekkit, if that's an important detail. Here's the script:


while true do
term.clear()
term.setCursorPos(1,1)
write([[
Welcome to the Exedra Pump System!
To turn the pumps on, please type "ON".
To turn the pumps off, please type "OFF".
The statuses are not case-sensitive.

STATUS:
]])
local input = io.read()
if string.lower(input) == "on" then
print("Redstone pumps turned on!") – this part won't show up
rs.setOutput("back",true)
elseif string.lower(input) == "off" then
print("Redstone pumps turned off!") – and this part.
rs.setOutput("back",false)
else
print("ERROR: "..input.." is not a valid status!")
sleep(2)
end
end

I'm sorry if it's not tabbed, I did tab it in notepad++, not sure if it works on forum posts. It's also the same for a redstone mechanic of mine. But it's similar to this. Thanks in advance for the help!
Fatal_Exception #2
Posted 13 October 2012 - 11:12 AM
They probably do show up, but then it jumps back to the start of the while loop and clears the screen. You probably want to sleep for a second or two, or os.pullEvent("key") to pause for key input.
TheOnlyExedra #3
Posted 13 October 2012 - 11:29 AM
They probably do show up, but then it jumps back to the start of the while loop and clears the screen. You probably want to sleep for a second or two, or os.pullEvent("key") to pause for key input.

So I'll need to make it sleep after every "if" or "elseif" like I did with the ending? I only did that to make the infinite loop slower to stop immense lag. But I'll try. Thanks!
Exerro #4
Posted 13 October 2012 - 11:32 AM
So I'll need to make it sleep after every "if" or "elseif" like I did with the ending? I only did that to make the infinite loop slower to stop immense lag. But I'll try. Thanks!
you need to make it sleep after a print otherwise it just clears it straight away