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

Help with a computer program for a nuke

Started by xaberranthianx, 17 December 2012 - 09:52 AM
xaberranthianx #1
Posted 17 December 2012 - 10:52 AM
As the title suggests, I am working on trying to do a simple code to help me get used to Lua. I've been learning Lua since yesterday so my experience is very limited. I was wondering if anyone could look at this code and tell me why it isn't working the way I intended it to.

What I'd like it to do is to first ask for a password. If you get it right, it activates the redstone beneath it which triggers the nuke, and then starts a countdown on screen from 20 to 0, and then reset back to the startup.

What it is doing right now, is when the password is correct, it activates the redstone and gives me my confirmation message, but then instead of a countdown starting it loops back to the password screen. I could have sworn I ended the loop but as I said I'm still new so I'm sure I made a mistake somewhere.

Also if anyone has any tips for helping me "clean up" my code work a little I'd love the feedback :)/>

Here's the code:

--[[
MAKE A DETONATE SEQUENCE THAT ACTIVATES THE NUKE AND STARTS A COUNTDOWN FROM 20 TO 0, THEN RESETS.
]]

s = 20 -- Variable for later in the countdown section

while true do
term.clear()
term.setCursorPos(1,1)
write ("Enter the password to start the detonation sequence: ")
local input = read()
    if input == "Nuketown" then
    term.clear()
    term.setCursorPos(1,1)
    write ("Correct. Starting detonation sequence.")
    sleep (2)
    rs.setOutput ("bottom", true)
    sleep (1)
    rs.setOutput ("bottom", false)
    else
    term.clear()
    term.setCursorPos(1,1)
    write ("Incorrect")
    sleep (2)
    end
end -- This is where it loops back to the first "while true do" function. So after correctly inputting the password and everything activating, it goes back through the loop.

while true do -- I want it to start here when the previous "end" is done, instead of loop back to the first "while true do" function
term.clear()
term.setCursorPos(1,1)
write ("Detonation in: "..s)

s = s-1

    if s == 0 then
    term.clear()
    term.setCursorPos(1,1)
    error()
    end
end
remiX #2
Posted 17 December 2012 - 11:03 AM
Untested but this should work. A for loop is perfect for a countdown :)/>

Spoiler

--[[
MAKE A DETONATE SEQUENCE THAT ACTIVATES THE NUKE AND STARTS A COUNTDOWN FROM 20 TO 0, THEN RESETS.
]]

s = 20 -- Variable for later in the countdown section
x, y = term.getSize()
done = false

function boom()
    term.clear()
    term.setCursorPos(1,1)
    term.setCursorPos((x-16)/2, y/2-1)
    write("Detonation in...")
    for i = s, 1, -1 do
        term.setCursorPos((x-2)/2, y/2)
        term.clearLine()
        write(i)
        sleep(1)
    end
    term.clear()
    term.setCursorPos((x-5)/2, y/2)
    write("BOOM!")
    sleep(5)
end
        
while not done do
term.clear()
term.setCursorPos(1,1)
print("Enter the password to start the detonation sequence: ")
write(" > ")
local input = read()
    if input == "Nuketown" then
        term.clear()
        term.setCursorPos(1,1)
        write("Correct. Starting detonation sequence in 2 seconds...")
        sleep (2)
        rs.setOutput ("bottom", true)
        rs.setOutput ("bottom", false)
        boom()
        done = true
    else
        term.clear()
        term.setCursorPos(1,1)
        write ("Incorrect")
        sleep (2)
    end
end

-- Clean up
term.clear()
term.setCursorPos(1,1)
theoriginalbit #3
Posted 17 December 2012 - 11:04 AM
Indenting will work wonders to clean up the code for a starters, (if you haven't of course, i kno how bad copy/paste to here can be :P/> )

the reason you don't see the countdown is its calculating from 20 to 0 too quick. slow it down in that loop with a sleep(1) before it loops back :)/>
xaberranthianx #4
Posted 17 December 2012 - 11:23 AM
Untested but this should work. A for loop is perfect for a countdown :)/>

Spoiler

--[[
MAKE A DETONATE SEQUENCE THAT ACTIVATES THE NUKE AND STARTS A COUNTDOWN FROM 20 TO 0, THEN RESETS.
]]

s = 20 -- Variable for later in the countdown section
x, y = term.getSize()
done = false

function boom()
	term.clear()
	term.setCursorPos(1,1)
	term.setCursorPos((x-16)/2, y/2-1)
	write("Detonation in...")
	for i = s, 1, -1 do
		term.setCursorPos((x-2)/2, y/2)
		term.clearLine()
		write(i)
		sleep(1)
	end
	term.clear()
	term.setCursorPos((x-5)/2, y/2)
	write("BOOM!")
	sleep(5)
end
		
while not done do
term.clear()
term.setCursorPos(1,1)
print("Enter the password to start the detonation sequence: ")
write(" > ")
local input = read()
	if input == "Nuketown" then
		term.clear()
		term.setCursorPos(1,1)
		write("Correct. Starting detonation sequence in 2 seconds...")
		sleep (2)
		rs.setOutput ("bottom", true)
		rs.setOutput ("bottom", false)
		boom()
		done = true
	else
		term.clear()
		term.setCursorPos(1,1)
		write ("Incorrect")
		sleep (2)
	end
end

-- Clean up
term.clear()
term.setCursorPos(1,1)

Woah….O.O' That's a lot of code that I've never seen before. lol. I'll test it to see if it works, but it would kinda defeat the whole purpose of learning how to make it cause I wouldn't be able to use the knowledge of knowing when to use these terms and such. Could you perhaps give me a quick description of what the changes you made do or mean? Thanks :P/>
xaberranthianx #5
Posted 17 December 2012 - 11:25 AM
Indenting will work wonders to clean up the code for a starters, (if you haven't of course, i kno how bad copy/paste to here can be :P/> )

the reason you don't see the countdown is its calculating from 20 to 0 too quick. slow it down in that loop with a sleep(1) before it loops back :)/>

Yeah this copy and paste business with Lua is a pain. As far as the "sleep()" function goes, where would I put it? I tried putting it in a few different places to no avail. It still just goes from deactivating the redstone right back to the "enter password" screen. it skips the countdown all together. Where would you put the "sleep(1)" at?
remiX #6
Posted 17 December 2012 - 11:30 AM
Yours is fine, I just like to use functions :P/> Your code just needed 2 breaks and a sleep(1) and it's fine:

--[[
MAKE A DETONATE SEQUENCE THAT ACTIVATES THE NUKE AND STARTS A COUNTDOWN FROM 20 TO 0, THEN RESETS.
]]

s = 20 -- Variable for later in the countdown section

while true do
term.clear()
term.setCursorPos(1,1)
write ("Enter the password to start the detonation sequence: ")
local input = read()
    if input == "Nuketown" then
        term.clear()
        term.setCursorPos(1,1)
        write ("Correct. Starting detonation sequence.")
        sleep (2)
        rs.setOutput ("bottom", true)
        sleep (1)
        rs.setOutput ("bottom", false)
        break  -- stop the loop
    else
        term.clear()
        term.setCursorPos(1,1)
        write ("Incorrect")
        sleep (2)
    end
end -- This is where it loops back to the first "while true do" function. So after correctly inputting the password and everything activating, it goes back through the loop.

while true do -- I want it to start here when the previous "end" is done, instead of loop back to the first "while true do" function
term.clear()
term.setCursorPos(1,1)
write ("Detonation in: "..s)

s = s-1

if s == 0 then
    term.clear()
    term.setCursorPos(1,1)
    break  -- stop the loop
end
    sleep(1)  -- To make it wait 1 second
end
theoriginalbit #7
Posted 17 December 2012 - 11:31 AM
from a quick look at what remiX did it looks like it should work… :)/>
xaberranthianx #8
Posted 17 December 2012 - 11:41 AM
Yours is fine, I just like to use functions :P/> Your code just needed 2 breaks and a sleep(1) and it's fine:

--[[
MAKE A DETONATE SEQUENCE THAT ACTIVATES THE NUKE AND STARTS A COUNTDOWN FROM 20 TO 0, THEN RESETS.
]]

s = 20 -- Variable for later in the countdown section

while true do
term.clear()
term.setCursorPos(1,1)
write ("Enter the password to start the detonation sequence: ")
local input = read()
	if input == "Nuketown" then
		term.clear()
		term.setCursorPos(1,1)
		write ("Correct. Starting detonation sequence.")
		sleep (2)
		rs.setOutput ("bottom", true)
		sleep (1)
		rs.setOutput ("bottom", false)
		break  -- stop the loop
	else
		term.clear()
		term.setCursorPos(1,1)
		write ("Incorrect")
		sleep (2)
	end
end -- This is where it loops back to the first "while true do" function. So after correctly inputting the password and everything activating, it goes back through the loop.

while true do -- I want it to start here when the previous "end" is done, instead of loop back to the first "while true do" function
term.clear()
term.setCursorPos(1,1)
write ("Detonation in: "..s)

s = s-1

if s == 0 then
	term.clear()
	term.setCursorPos(1,1)
	break  -- stop the loop
end
	sleep(1)  -- To make it wait 1 second
end

HAHA! Wow. I've heard of breaks before from searching around forums but didn't know they did that. Good to know. Thanks! Also, your code worked also, and after I used it and saw what it did, I noticed that you CREATED the function prior to making the program, and then inserted the function (in this case, Boom()) when you wanted it to happen :P/> At least I THINK that's what you did. As for the x,y business, I'm guessing those were just coordinates for where the text would be displayed on screen? The only thing I had to add to your code to make it work was the -sleep(1)- between the redstone activate/deactivate functions. They seemed to just cancel eachother out and sent no signal before counting down but the sleep(1) fixed it. Thanks you two!
theoriginalbit #9
Posted 17 December 2012 - 11:47 AM
Yours is fine, I just like to use functions :P/> Your code just needed 2 breaks and a sleep(1) and it's fine:

--[[
MAKE A DETONATE SEQUENCE THAT ACTIVATES THE NUKE AND STARTS A COUNTDOWN FROM 20 TO 0, THEN RESETS.
]]

s = 20 -- Variable for later in the countdown section

while true do
term.clear()
term.setCursorPos(1,1)
write ("Enter the password to start the detonation sequence: ")
local input = read()
	if input == "Nuketown" then
		term.clear()
		term.setCursorPos(1,1)
		write ("Correct. Starting detonation sequence.")
		sleep (2)
		rs.setOutput ("bottom", true)
		sleep (1)
		rs.setOutput ("bottom", false)
		break  -- stop the loop
	else
		term.clear()
		term.setCursorPos(1,1)
		write ("Incorrect")
		sleep (2)
	end
end -- This is where it loops back to the first "while true do" function. So after correctly inputting the password and everything activating, it goes back through the loop.

while true do -- I want it to start here when the previous "end" is done, instead of loop back to the first "while true do" function
term.clear()
term.setCursorPos(1,1)
write ("Detonation in: "..s)

s = s-1

if s == 0 then
	term.clear()
	term.setCursorPos(1,1)
	break  -- stop the loop
end
	sleep(1)  -- To make it wait 1 second
end

HAHA! Wow. I've heard of breaks before from searching around forums but didn't know they did that. Good to know. Thanks! Also, your code worked also, and after I used it and saw what it did, I noticed that you CREATED the function prior to making the program, and then inserted the function (in this case, Boom()) when you wanted it to happen :P/> At least I THINK that's what you did. As for the x,y business, I'm guessing those were just coordinates for where the text would be displayed on screen? The only thing I had to add to your code to make it work was the -sleep(1)- between the redstone activate/deactivate functions. They seemed to just cancel eachother out and sent no signal before counting down but the sleep(1) fixed it. Thanks you two!

functions must always be declared before trying to use them in a procedural language (there are a few exceptions, lua isn't one :P/> )

as for the sleep. sleep(0.1) should be enough
remiX #10
Posted 17 December 2012 - 11:55 AM
HAHA! Wow. I've heard of breaks before from searching around forums but didn't know they did that. Good to know. Thanks!

What else would they have done? :P/>

Also, your code worked also, and after I used it and saw what it did, I noticed that you CREATED the function prior to making the program, and then inserted the function (in this case, Boom()) when you wanted it to happen :P/> At least I THINK that's what you did.

Yeah as TheOriginalBit said, you need to declare the functions before calling them. It just neatens up code a bit.

As for the x,y business, I'm guessing those were just coordinates for where the text would be displayed on screen?

Yeah all the minusing and dividing was just to get it to center to make it look nice :P/>

The only thing I had to add to your code to make it work was the -sleep(1)- between the redstone activate/deactivate functions. They seemed to just cancel eachother out and sent no signal before counting down but the sleep(1) fixed it. Thanks you two!

Mm, you sure? I've heard that you don't need an interval between switching redstone signals on and off. But glad to know it works :)/>
xaberranthianx #11
Posted 17 December 2012 - 12:00 PM
HAHA! Wow. I've heard of breaks before from searching around forums but didn't know they did that. Good to know. Thanks!

What else would they have done? :P/>

Also, your code worked also, and after I used it and saw what it did, I noticed that you CREATED the function prior to making the program, and then inserted the function (in this case, Boom()) when you wanted it to happen :P/> At least I THINK that's what you did.

Yeah as TheOriginalBit said, you need to declare the functions before calling them. It just neatens up code a bit.

As for the x,y business, I'm guessing those were just coordinates for where the text would be displayed on screen?

Yeah all the minusing and dividing was just to get it to center to make it look nice :P/>

The only thing I had to add to your code to make it work was the -sleep(1)- between the redstone activate/deactivate functions. They seemed to just cancel eachother out and sent no signal before counting down but the sleep(1) fixed it. Thanks you two!

Mm, you sure? I've heard that you don't need an interval between switching redstone signals on and off. But glad to know it works :)/>

Yeah. I ran the program as you had it and it ran everything fine but it never activated the redstone. No biggy. Typing another line isn't an issue. I'm actually gonna use your example to try and modify to create different uses. Haha. It's what I do with everything I learn. Reproducing the exact thing every time is nice and all, but modifying it slightly and watching the results is more satisfying (sometimes :P/>) That's how I came up with this idea. I saw a timer program online, then saw a redstone tutorial for the computer online, and combined them both together to try and get my desired results. It's entertaining at the least. Except that I spent two hours trying to fix the issue before coming to the threads haha. But I'm glad I did cause you guys rock! I never thought programming would become so addicting to learn and write.
theoriginalbit #12
Posted 17 December 2012 - 12:02 PM
yeh there needs to be at least a tick of delay between setting the redstone on and off. one tick should be about 0.05 of a delay if im not mistaken
xaberranthianx #13
Posted 17 December 2012 - 12:10 PM
yeh there needs to be at least a tick of delay between setting the redstone on and off. one tick should be about 0.05 of a delay if im not mistaken

That's right. I forgot you could use less than 1 second in the sleep function. I tested out my modified original file with the .1 sleep and it worked. lol. Just spent 3 hours on a simple function. Hooray me. xD I can only imagine how much time a complex program would take to write.
theoriginalbit #14
Posted 17 December 2012 - 12:21 PM
haha. I've been working on one of mine for about a week now.
xaberranthianx #15
Posted 17 December 2012 - 12:51 PM
haha. I've been working on one of mine for about a week now.

A program for minecraft or a windows program?
theoriginalbit #16
Posted 17 December 2012 - 12:54 PM
haha. I've been working on one of mine for about a week now.

A program for minecraft or a windows program?

For CC. I've been working on my Minecraft Mod for months. And my PC/Mac/Linux program for months too.
xaberranthianx #17
Posted 17 December 2012 - 01:06 PM
Nice! I hope everything is coming along well. If you don't mind me asking, what's the mod you're making for Minecraft? Or what is the idea?
theoriginalbit #18
Posted 17 December 2012 - 01:13 PM
Nice! I hope everything is coming along well. If you don't mind me asking, what's the mod you're making for Minecraft? Or what is the idea?

Thats a secret ;)/> :P/> sorry
Dlcruz129 #19
Posted 17 December 2012 - 02:04 PM
Yours is fine, I just like to use functions :P/> Your code just needed 2 breaks and a sleep(1) and it's fine:

--[[
MAKE A DETONATE SEQUENCE THAT ACTIVATES THE NUKE AND STARTS A COUNTDOWN FROM 20 TO 0, THEN RESETS.
]]

s = 20 -- Variable for later in the countdown section

while true do
term.clear()
term.setCursorPos(1,1)
write ("Enter the password to start the detonation sequence: ")
local input = read()
	if input == "Nuketown" then
		term.clear()
		term.setCursorPos(1,1)
		write ("Correct. Starting detonation sequence.")
		sleep (2)
		rs.setOutput ("bottom", true)
		sleep (1)
		rs.setOutput ("bottom", false)
		break  -- stop the loop
	else
		term.clear()
		term.setCursorPos(1,1)
		write ("Incorrect")
		sleep (2)
	end
end -- This is where it loops back to the first "while true do" function. So after correctly inputting the password and everything activating, it goes back through the loop.

while true do -- I want it to start here when the previous "end" is done, instead of loop back to the first "while true do" function
term.clear()
term.setCursorPos(1,1)
write ("Detonation in: "..s)

s = s-1

if s == 0 then
	term.clear()
	term.setCursorPos(1,1)
	break  -- stop the loop
end
	sleep(1)  -- To make it wait 1 second
end

HAHA! Wow. I've heard of breaks before from searching around forums but didn't know they did that. Good to know. Thanks! Also, your code worked also, and after I used it and saw what it did, I noticed that you CREATED the function prior to making the program, and then inserted the function (in this case, Boom()) when you wanted it to happen :P/> At least I THINK that's what you did. As for the x,y business, I'm guessing those were just coordinates for where the text would be displayed on screen? The only thing I had to add to your code to make it work was the -sleep(1)- between the redstone activate/deactivate functions. They seemed to just cancel eachother out and sent no signal before counting down but the sleep(1) fixed it. Thanks you two!

functions must always be declared before trying to use them in a procedural language (there are a few exceptions, lua isn't one :P/> )

as for the sleep. sleep(0.1) should be enough

Its a 20-second countdown.
theoriginalbit #20
Posted 17 December 2012 - 02:09 PM
Yours is fine, I just like to use functions :P/> Your code just needed 2 breaks and a sleep(1) and it's fine:

--[[
MAKE A DETONATE SEQUENCE THAT ACTIVATES THE NUKE AND STARTS A COUNTDOWN FROM 20 TO 0, THEN RESETS.
]]

s = 20 -- Variable for later in the countdown section

while true do
term.clear()
term.setCursorPos(1,1)
write ("Enter the password to start the detonation sequence: ")
local input = read()
	if input == "Nuketown" then
		term.clear()
		term.setCursorPos(1,1)
		write ("Correct. Starting detonation sequence.")
		sleep (2)
		rs.setOutput ("bottom", true)
		sleep (1)
		rs.setOutput ("bottom", false)
		break  -- stop the loop
	else
		term.clear()
		term.setCursorPos(1,1)
		write ("Incorrect")
		sleep (2)
	end
end -- This is where it loops back to the first "while true do" function. So after correctly inputting the password and everything activating, it goes back through the loop.

while true do -- I want it to start here when the previous "end" is done, instead of loop back to the first "while true do" function
term.clear()
term.setCursorPos(1,1)
write ("Detonation in: "..s)

s = s-1

if s == 0 then
	term.clear()
	term.setCursorPos(1,1)
	break  -- stop the loop
end
	sleep(1)  -- To make it wait 1 second
end

HAHA! Wow. I've heard of breaks before from searching around forums but didn't know they did that. Good to know. Thanks! Also, your code worked also, and after I used it and saw what it did, I noticed that you CREATED the function prior to making the program, and then inserted the function (in this case, Boom()) when you wanted it to happen :P/> At least I THINK that's what you did. As for the x,y business, I'm guessing those were just coordinates for where the text would be displayed on screen? The only thing I had to add to your code to make it work was the -sleep(1)- between the redstone activate/deactivate functions. They seemed to just cancel eachother out and sent no signal before counting down but the sleep(1) fixed it. Thanks you two!

functions must always be declared before trying to use them in a procedural language (there are a few exceptions, lua isn't one :P/> )

as for the sleep. sleep(0.1) should be enough

Its a 20-second countdown.

your point?
xaberranthianx #21
Posted 17 December 2012 - 02:20 PM
Nice! I hope everything is coming along well. If you don't mind me asking, what's the mod you're making for Minecraft? Or what is the idea?

Thats a secret ;)/> :P/> sorry

Fair enough :P/> Whatever it is, I hope to see it available someday! :D/> Good luck, and may the coding force be with you. ;)/>
Dlcruz129 #22
Posted 17 December 2012 - 02:29 PM
Yours is fine, I just like to use functions :P/>/> Your code just needed 2 breaks and a sleep(1) and it's fine:

--[[
MAKE A DETONATE SEQUENCE THAT ACTIVATES THE NUKE AND STARTS A COUNTDOWN FROM 20 TO 0, THEN RESETS.
]]

s = 20 -- Variable for later in the countdown section

while true do
term.clear()
term.setCursorPos(1,1)
write ("Enter the password to start the detonation sequence: ")
local input = read()
	if input == "Nuketown" then
		term.clear()
		term.setCursorPos(1,1)
		write ("Correct. Starting detonation sequence.")
		sleep (2)
		rs.setOutput ("bottom", true)
		sleep (1)
		rs.setOutput ("bottom", false)
		break  -- stop the loop
	else
		term.clear()
		term.setCursorPos(1,1)
		write ("Incorrect")
		sleep (2)
	end
end -- This is where it loops back to the first "while true do" function. So after correctly inputting the password and everything activating, it goes back through the loop.

while true do -- I want it to start here when the previous "end" is done, instead of loop back to the first "while true do" function
term.clear()
term.setCursorPos(1,1)
write ("Detonation in: "..s)

s = s-1

if s == 0 then
	term.clear()
	term.setCursorPos(1,1)
	break  -- stop the loop
end
	sleep(1)  -- To make it wait 1 second
end

HAHA! Wow. I've heard of breaks before from searching around forums but didn't know they did that. Good to know. Thanks! Also, your code worked also, and after I used it and saw what it did, I noticed that you CREATED the function prior to making the program, and then inserted the function (in this case, Boom()) when you wanted it to happen :P/>/> At least I THINK that's what you did. As for the x,y business, I'm guessing those were just coordinates for where the text would be displayed on screen? The only thing I had to add to your code to make it work was the -sleep(1)- between the redstone activate/deactivate functions. They seemed to just cancel eachother out and sent no signal before counting down but the sleep(1) fixed it. Thanks you two!

functions must always be declared before trying to use them in a procedural language (there are a few exceptions, lua isn't one :P/>/> )

as for the sleep. sleep(0.1) should be enough

Its a 20-second countdown.

your point?

If it was sleep(0.01), the thing would be done in .2 seconds.
theoriginalbit #23
Posted 17 December 2012 - 02:34 PM
Nice! I hope everything is coming along well. If you don't mind me asking, what's the mod you're making for Minecraft? Or what is the idea?

Thats a secret ;)/> :P/> sorry

Fair enough :P/> Whatever it is, I hope to see it available someday! :D/> Good luck, and may the coding force be with you. ;)/>

thank you :)/>

Yours is fine, I just like to use functions :P/>/> Your code just needed 2 breaks and a sleep(1) and it's fine:

--[[
MAKE A DETONATE SEQUENCE THAT ACTIVATES THE NUKE AND STARTS A COUNTDOWN FROM 20 TO 0, THEN RESETS.
]]

s = 20 -- Variable for later in the countdown section

while true do
term.clear()
term.setCursorPos(1,1)
write ("Enter the password to start the detonation sequence: ")
local input = read()
	if input == "Nuketown" then
		term.clear()
		term.setCursorPos(1,1)
		write ("Correct. Starting detonation sequence.")
		sleep (2)
		rs.setOutput ("bottom", true)
		sleep (1)
		rs.setOutput ("bottom", false)
		break  -- stop the loop
	else
		term.clear()
		term.setCursorPos(1,1)
		write ("Incorrect")
		sleep (2)
	end
end -- This is where it loops back to the first "while true do" function. So after correctly inputting the password and everything activating, it goes back through the loop.

while true do -- I want it to start here when the previous "end" is done, instead of loop back to the first "while true do" function
term.clear()
term.setCursorPos(1,1)
write ("Detonation in: "..s)

s = s-1

if s == 0 then
	term.clear()
	term.setCursorPos(1,1)
	break  -- stop the loop
end
	sleep(1)  -- To make it wait 1 second
end

HAHA! Wow. I've heard of breaks before from searching around forums but didn't know they did that. Good to know. Thanks! Also, your code worked also, and after I used it and saw what it did, I noticed that you CREATED the function prior to making the program, and then inserted the function (in this case, Boom()) when you wanted it to happen :P/>/> At least I THINK that's what you did. As for the x,y business, I'm guessing those were just coordinates for where the text would be displayed on screen? The only thing I had to add to your code to make it work was the -sleep(1)- between the redstone activate/deactivate functions. They seemed to just cancel eachother out and sent no signal before counting down but the sleep(1) fixed it. Thanks you two!

functions must always be declared before trying to use them in a procedural language (there are a few exceptions, lua isn't one :P/>/> )

as for the sleep. sleep(0.1) should be enough

Its a 20-second countdown.

your point?

If it was sleep(0.01), the thing would be done in .2 seconds.

if you were following along the sleep(0.01) is for the minimum delay between the redstone being turned on and off