571 posts
Location
Some Fish Bowl in Ohio.
Posted 05 October 2013 - 11:30 AM
Hi, I have had ComputerCraft for a while, but I mainly use it to see what OTHER people create. However I did work up the ambition to write my own code to make firing a tnt cannon easier. Here is what i have so far.
print"The TNT will now fire at the village"
redstone.setOutput("back",true)
sleep(.1)
redstone.setOutput("back",false)
sleep(6)
print"Confirmed hit!"
sleep(1.5)
term.clear()
term.setCursorPos(1, 1)
print"Type Launch to fire again"
io.read()
io.read = input
if
input == "Launch"
then do
redstone.setOutput("back",true)
sleep(.1)
redstone.setOutput("back",false)
end
else
os.reboot()
end
The problem is, when I type "Launch", it does os.reboot() instead of doing the "then" command. Can someone help? Thanks :)/>
8543 posts
Posted 05 October 2013 - 03:45 PM
Split into new topic.
997 posts
Location
Wellington, New Zealand
Posted 05 October 2013 - 03:49 PM
io.read()
Read a line of text. Throw away the result.
io.read = input
input is nil at this point, because nil is the default value for variables and you haven't set it to anything. This line sets io.read to nil, so that nobody else can use it to read a line of text.
if
input == "Launch"
then
Checks if input contains "Launch", which it doesn't, because it contains nil.
Instead of this:
io.read()
io.read = input
you probably meant this:
input = io.read()
571 posts
Location
Some Fish Bowl in Ohio.
Posted 07 October 2013 - 11:39 AM
io.read()
Read a line of text. Throw away the result.
io.read = input
input is nil at this point, because nil is the default value for variables and you haven't set it to anything. This line sets io.read to nil, so that nobody else can use it to read a line of text.
if
input == "Launch"
then
Checks if input contains "Launch", which it doesn't, because it contains nil.
Instead of this:
io.read()
io.read = input
you probably meant this:
input = io.read()
Thank you! It worked!
331 posts
Posted 08 October 2013 - 05:40 AM
just a note I don't think your understanding if statements they are like
if something then
not
if something then do
the only reason this works is because Lua (not LUA) has do statements
571 posts
Location
Some Fish Bowl in Ohio.
Posted 08 October 2013 - 09:53 AM
just a note I don't think your understanding if statements they are like
if something then
not
if something then do
the only reason this works is because Lua (not LUA) has do statements
You seem to know what you are doing, how would I make the "Type launch to fire again" Loop until you want to stop?
1114 posts
Location
UK
Posted 09 October 2013 - 12:57 PM
while true do
-- code
-- code
if condition then -- Check if you want to stop
break -- Stop
end
end