Jump to content


xaberranthianx's Content

There have been 9 items by xaberranthianx (Search limited from 29-March 23)


By content type

See this member's

Sort by                Order  

#60836 Help with a computer program for a nuke

Posted by xaberranthianx on 17 December 2012 - 02:20 PM in Ask a Pro

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



#60812 Help with a computer program for a nuke

Posted by xaberranthianx on 17 December 2012 - 01:06 PM in Ask a Pro

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?



#60804 Help with a computer program for a nuke

Posted by xaberranthianx on 17 December 2012 - 12:51 PM in Ask a Pro

View PostTheOriginalBIT, on 17 December 2012 - 12:21 PM, said:

haha. I've been working on one of mine for about a week now.

A program for minecraft or a windows program?



#60791 Help with a computer program for a nuke

Posted by xaberranthianx on 17 December 2012 - 12:10 PM in Ask a Pro

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

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.



#60786 Help with a computer program for a nuke

Posted by xaberranthianx on 17 December 2012 - 12:00 PM in Ask a Pro

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

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

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

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

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.

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

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

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

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.



#60780 Help with a computer program for a nuke

Posted by xaberranthianx on 17 December 2012 - 11:41 AM in Ask a Pro

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!



#60761 Help with a computer program for a nuke

Posted by xaberranthianx on 17 December 2012 - 11:25 AM in Ask a Pro

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

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?



#60757 Help with a computer program for a nuke

Posted by xaberranthianx on 17 December 2012 - 11:23 AM in Ask a Pro

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

Untested but this should work. A for loop is perfect for a countdown :)

Spoiler

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



#60730 Help with a computer program for a nuke

Posted by xaberranthianx on 17 December 2012 - 10:52 AM in Ask a Pro

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