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

Countdown time within another function

Started by slashv2, 13 March 2013 - 04:18 AM
slashv2 #1
Posted 13 March 2013 - 05:18 AM
Hi, made a little mob farm on my server. and i got it up an running, but now. im thinking of adding a count down timer to it, and have written a count down code.

but how would i make the timer run 60 times (count down from 60) within my Text function?

Any help or tips are more then welcome :D/>

(and yes, i could just have used one computer for to turn the mobs on, maybe next time)

term.clear()
rednet.open("right")
mon = peripheral.wrap("bottom")

print("					   Menu")
print("				  --------------")
print("				    1.Creeper")
print("				    2.Zombie")
print("				    3.Skeleton")
print("				    4.Pigman")
print("				    5.Tons of xp!")
print("				  --------------")
print("				    Enter number")
print("					   1 - 5")
print("				  --------------")
print("		    Please enter only one command")
print("			  The system will auto reset")
print("					 after 1 min")

name = io.read()

function text()
	    print("			 ----------------------------")
	    print("			 The system will run for 1min")
	    print("				  Then auto restart")
	    print("			   Please wait till it's done")
	    print("			 ----------------------------")
sleep(60)
os.reboot()
end

function timer()
count = 60
repeat
while true do
  term.setCursorPos(1,1)
   term.redirect(mon)
    mon.setTextScale(3)
	 term.clear()
	  count = count -1
	   print(count)
	    sleep(1)
end
end

if name == "1" then
rednet.send(17,"creeper")
  term.clear()
   text()

elseif name == "2" then
rednet.send(18,"creeper")
  term.clear()
   text()

elseif name == "3" then
rednet.send(19,"Skeleton")
  term.clear()
   text()


elseif name == "4" then
rednet.send(18,"Pigman")
  term.clear()
   text()


elseif name == "5" then
term.clear()
	    print("			 ----------------------------")
	    print("			  Will you be needing a book?")
	    print("			 ----------------------------")
	    print("					    yes/no")
	    print("			 ----------------------------")
name = io.read()

if name == "yes" then
rs.setOutput("top",true)
  sleep(1)
   rs.setOutput("top",false)
    rednet.send(17,"Creeper")
	 rednet.send(18,"zombie")
	  rednet.send(19,"skeleton")
	   term.clear()
	    text()

elseif name == "no" then
rednet.send(17,"Creeper")
  rednet.send(18,"zombie")
   rednet.send(19,"skeleton")
    term.clear()
	 text()

end
end
Bubba #2
Posted 13 March 2013 - 05:37 AM
So what you want is for the text function to display a timer that counts down as well as the text? You should include the timer in the text function and use for loops.

Example:

local function text()
  for i=60,1,-1 do
  term.clear()
  term.setCursorPos(1,1)
  print("Time left: "..i)
  print("You stuff")
  print("other stuff")
  print([[You know you can
  also use multiline
  strings to do this.]])
  sleep(1)
  end
end
Lyqyd #3
Posted 13 March 2013 - 05:40 AM
Be careful with indentation and block quotes–they will include the indentation in the string!
slashv2 #4
Posted 13 March 2013 - 05:55 AM
Well that was sure a more easy way of doing it :P/> thanks