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

Wait for input

Started by gheotic, 21 July 2012 - 10:13 AM
gheotic #1
Posted 21 July 2012 - 12:13 PM
Hello every one who is reading this
i need some help with my script
i need a way to tell the script that it should wait till the var has a input

just wanna make a easy script for my information monitor, so i can easy just type what i want to write on the monitor then i writes it.
Can anyone help?
Grim Reaper #2
Posted 21 July 2012 - 12:16 PM
The standard read function already waits until the user presses enter. However, if you are looking for something that will not execute until your variable is actually equal to something that a user inputs, then you could try this:


sInput = nil

while true do
   sInput = read()
   if sInput ~= nil or sInput ~= "" then
	 break -- Break out of the infinite loop
	  -- Monitor code goes here
   end
end

Look into the ComputerCraft Wiki; it should answer a lot of questions for you.

Hope I helped! :)/>/>
gheotic #3
Posted 21 July 2012 - 12:57 PM
Thanks a lot =)
give me a better idea how it works =)

this is the code so fare

sInput = nil
peripheral.wrap("right")
print("what do you want to print?")
while true do
   sInput = read()
   if sInput ~ nil or sInput ~ "" then
		 break -- Break out of the infinite loop
  
term.setCurorPos(1, 1)
monitor.setTextScale(3)
monitor.write(""..sInput..")
		  -- Monitor code goes here
   end
end

but i get this error
bios:206: [string "monitortest"]:9: 'then' expected
have i made a mistake?
Exerro #4
Posted 21 July 2012 - 06:16 PM
term.setCursorPos not term.setCurorPos just a typo
Grim Reaper #5
Posted 22 July 2012 - 05:25 AM
term.setCursorPos not term.setCurorPos just a typo
Plus one :)/>/>

Old code:

sInput = nil
peripheral.wrap("right")
print("what do you want to print?")
while true do
   sInput = read()
   if sInput ~ nil or sInput ~ "" then
				 break -- Break out of the infinite loop

term.setCurorPos(1, 1)
monitor.setTextScale(3)
monitor.write(""..sInput..")
				  -- Monitor code goes here
   end
end

New code:

sInput = nil
peripheral.wrap("right")
print("what do you want to print?")
while true do
   sInput = read()
   if sInput ~ nil or sInput ~ "" then
				 break -- Break out of the infinite loop

term.setCusrorPos(1, 1) -- Now term.setCursorPos( ... ) as opposed to term.setCurorPos( ... )
monitor.setTextScale(3)
monitor.write(""..sInput..")
				  -- Monitor code goes here
   end
end
Lyqyd #6
Posted 22 July 2012 - 06:09 AM
Why did you start two topics for this?