64 posts
Location
Denmark
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?
504 posts
Location
Seattle, WA
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! :)/>/>
64 posts
Location
Denmark
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' expectedhave i made a mistake?
797 posts
Posted 21 July 2012 - 06:16 PM
term.setCursorPos not term.setCurorPos just a typo
504 posts
Location
Seattle, WA
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
8543 posts
Posted 22 July 2012 - 06:09 AM
Why did you start two topics for this?