3 posts
Posted 24 February 2012 - 01:11 PM
clearscreen()
print "Starting..."
redstone.setOutput("left" , true)
print "Loading Cannon..."
sleep(2)
print "Releasing Cannonball"
redstone.setOutput("right" , true)
print "Firing!"
redstone.setOutput("left" , false)
redstone.setOutput("right" , false)
sleep(3)
print "Reload Cannon."
end
That is my code at the moment to fire a cannon.
If i try to execute the program, i get this error.
[string "cannon"]:16: '<eof>' expected
I know this is because of the "end" So at first i removed it.
I then got the error:
"attempt to call nil"
I thought "Maybe i have to add an "end""
So i did.
[string "cannon"]:16: '<eof>' expected
The point is im fresh out of ideas… I need some help :huh:/>/>
715 posts
Posted 24 February 2012 - 01:26 PM
Is that your whole code? If so then
clearscreen() is your problem.
You didn't define that function. If you want to clear the screen, then the correct command is:
term.clear()For more info on term-commands, type:
help termAlso for any future errors, take a look at this:
http://www.computercraft.info/forums2/index.php?/topic/118-codex-of-error-slaying-2/
Edited on 24 February 2012 - 12:30 PM
3 posts
Posted 24 February 2012 - 01:34 PM
Thanks i fixed it :huh:/>/>
But now what i want to add is an interface which triggers the mentioned code when the button "F" is pressed.
I made an Interface.
print "============================"
print " Press [F] to fire cannon "
print "============================"
I want this to stay on the computer until F is pressed.
F will trigger the code that i just fixed. How can i do this?
715 posts
Posted 24 February 2012 - 01:45 PM
Spoiler
while true do
term.clear()
print "============================"
print " Press [F] to fire cannon "
print "============================"
local event, param = os.pullEvent()
if event == "char" and param == "f" then
term.clear()
print "Starting..."
redstone.setOutput("left" , true)
print "Loading Cannon..."
sleep(2)
print "Releasing Cannonball"
redstone.setOutput("right" , true)
print "Firing!"
redstone.setOutput("left" , false)
redstone.setOutput("right" , false)
sleep(3)
print "Reload Cannon, then press ENTER."
read()
end
end
If you're on CC 1.3, then you can filter the watched events and thus shorten your code a
tiny bit:
Spoiler
while true do
term.clear()
print "============================"
print " Press [F] to fire cannon "
print "============================"
local event, param = os.pullEvent("char")
if param == "f" then
term.clear()
print "Starting..."
redstone.setOutput("left" , true)
print "Loading Cannon..."
sleep(2)
print "Releasing Cannonball"
redstone.setOutput("right" , true)
print "Firing!"
redstone.setOutput("left" , false)
redstone.setOutput("right" , false)
sleep(3)
print "Reload Cannon, then press ENTER."
read()
end
end
Disclaimer: Haven't tested any of the code in-game, should work thought.
If you want to know more about events, type:
help eventsEDIT: Forgot an "if" in front of "param" in my second code example. Fixed.
Edited on 24 February 2012 - 01:10 PM
3 posts
Posted 24 February 2012 - 01:52 PM
Worked perfectly other than it keeps scrolling down until the interface reaches the bottom of the screen.
How can i make it stay at the top?
Thanks for your help.
715 posts
Posted 24 February 2012 - 02:09 PM
That's because
term.clear() only clears the screen, but it doesn't change the cursor position.
If you want the cursor to be set to position 1, 1 then you have to use
term.setCursorPos(1, 1) like so:
while true do
term.setCursorPos(1, 1)
term.clear()
print "============================"
print " Press [F] to fire cannon "
print "============================"
local event, param = os.pullEvent("char")
if param == "f" then
term.clear()
print "Starting..."
redstone.setOutput("left" , true)
print "Loading Cannon..."
sleep(2)
print "Releasing Cannonball"
redstone.setOutput("right" , true)
print "Firing!"
redstone.setOutput("left" , false)
redstone.setOutput("right" , false)
sleep(3)
print "Reload Cannon, then press ENTER."
read()
end
end
EDIT:
Hmm, something odd is going on that I can't see atm. Will report back when I found out why.Nvm, the odd thing oddly vanished by itself. :huh:/>/>
Edited on 24 February 2012 - 01:20 PM