Jump to content




Help with a computer program for a nuke


22 replies to this topic

#21 xaberranthianx

  • New Members
  • 9 posts

Posted 17 December 2012 - 02:20 PM

View PostTheOriginalBIT, on 17 December 2012 - 01:13 PM, said:

View Postxaberranthianx, on 17 December 2012 - 01:06 PM, said:

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. ;)

#22 Dlcruz129

    What's a Lua?

  • Members
  • 1,423 posts

Posted 17 December 2012 - 02:29 PM

View PostTheOriginalBIT, on 17 December 2012 - 02:09 PM, said:

View PostDlcruz129, on 17 December 2012 - 02:04 PM, said:

View PostTheOriginalBIT, on 17 December 2012 - 11:47 AM, said:

View Postxaberranthianx, on 17 December 2012 - 11:41 AM, said:

View PostremiX, on 17 December 2012 - 11:30 AM, said:

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.

#23 theoriginalbit

    Semi-Professional ComputerCrafter

  • Moderators
  • 7,332 posts
  • LocationAustralia

Posted 17 December 2012 - 02:34 PM

View Postxaberranthianx, on 17 December 2012 - 02:20 PM, said:

View PostTheOriginalBIT, on 17 December 2012 - 01:13 PM, said:

View Postxaberranthianx, on 17 December 2012 - 01:06 PM, said:

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 :)

View PostDlcruz129, on 17 December 2012 - 02:29 PM, said:

View PostTheOriginalBIT, on 17 December 2012 - 02:09 PM, said:

View PostDlcruz129, on 17 December 2012 - 02:04 PM, said:

View PostTheOriginalBIT, on 17 December 2012 - 11:47 AM, said:

View Postxaberranthianx, on 17 December 2012 - 11:41 AM, said:

View PostremiX, on 17 December 2012 - 11:30 AM, said:

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





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users