Posted 17 March 2013 - 12:39 AM
Well as the title says I need help with creating a coroutine timer since I haven't quite figured out how I should do one..
I need it for returning how long time it has passed after I've completed this game.
————-
pastebin get B2A21J5z typer
I need it for returning how long time it has passed after I've completed this game.
Spoiler
os.pullEvent = os.pullEventRaw
function cleanScreen()
term.clear()
term.setCursorPos(1,1)
end
function drawAt(x,y,text)
term.setCursorPos(x,y)
write(text)
end
function randomWord()
t_words = {
"Ain't", "Bodywax", "Order", "Bunny", "Razor", "Nobody", "Calculator", "Malicious", "Eraser", "Banana",
"Remote Control", "25000$", "Alphabetical", "XXmyNameIsAwesome@hotmail.comXX", "Nuclear", "Atomic",
"Listen", "Rednet", "textutils.slowPrint[[Hello World]]", "This is Sparta!!", "[SPOILER] This is a spoiler [/SPOILER]",
"Programmer", "Boxer Tournament", "Chuck Testa", "term.clear() term.setCursorPos(1,1)", "Alphabetical", "Einstein",
"Clock", "Minecraft", "Moddable", "Mods", "Moderators", "T-rex", "Dinosaur", "Deforestation", "Landslide", "Heat wave",
"Hacker", "Invincible", "MMORPG", "Doctor", "Teacher", "Professor", "Fireman", "Police Officer", "Pilot", "Creativity",
"Valentines Day", "Hipster", "Fear", "Sadness", "Bravery", "Genius", "Dumb", "Slow", "Preservation", "Public", "Throught",
"With", "Itch", "Flying", "Width", "Height", "Lenght", "Isotremic", "Pixel", "Buffer", "Thunder", "Storm", "Volcano",
"Overpowered", "League Of Legends", "Laughing out loud", "Rolling on the floor laughing", "Shake", "Pain", "Side", "Ice",
"Ice age", "Ears", "Stomache", "Headache", "Electric", "Figure", "Laundry", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday", "Sunday", "Harlem", "Poison", "Headphones", "Robots", "R2D2", "C3PO", "Bobba Fett", "Luke Skywalker",
"Yoda", "Chewbacca", "Darth Vader", "Coroutines", "Drinking", "Alive", "Die", "Dead", "Beers", "Bears", "Beer", "Bear",
"Baby", "Babies", "Rockstar", "Red Bull", "Ronin", "Monster", "Shark", "Burn", "High", "Dressed", "Boys", "Girls", "Sleep",
"Awakened", "Changed", "My", "Mind", "Intentions", "Feelings", "Charity", "Office", "Five finger fillet", "Person",
"Went", "Live", "Computer", "ComputerCraft", "CraftOS", "Scratch", "Floor", "Lamp", "Wall", "Boat", "Ceiling", "Vain",
"Unlisted", "Smart", "Fast", "Double brackets", "String", "Table", "end", "%appdata%", "Yeah", "Choices", "Darling",
"Guitar", "Hero", "Drums", "Singer", "Piano", "Keyboard", "Filth", "City", "Town", "River", "Last", "Standing",
}
word = t_words[math.random(1, #t_words)]
end
function game()
finished = false
ran = 0
words = 0
newWord = true
while true do
if finished == true then
term.clear()
term.setCursorPos(1,1)
print("You Have Completed The Task")
print("TIME:"..time)
sleep(2)
break
end
time = os.clock()
if newWord == true then
randomWord()
end
if words == num then
term.clear()
term.setCursorPos(1,1)
print[[
.-=========-.
\'-=======-'/
_| .=. |_
((| {{1}} |))
\| /|\ |/
\__ ''' __/
_') ('_
_/_______\_
/___________\
You Have Won
Press any key to continue
]]
sleep(1)
os.pullEvent("key")
term.clear()
term.setCursorPos(1,1)
if term.isColor() then
term.setTextColor(colors.yellow)
end
print("STATS")
print("")
print("WORDS: "..num)
if term.isColor() then
term.setTextColor(colors.red)
end
print("FAILS: "..fails)
print("")
if term.isColor() then
term.setTextColor(colors.white)
end
print("Press any key to continue")
sleep(1)
os.pullEvent("key")
term.clear()
term.setCursorPos(1,1)
break
end
term.clear()
term.setCursorPos(1,1)
print("Word: "..word)
input = read()
if input == word then
newWord = true
words = words + 1
elseif input ~= word then
fails = fails + 1
newWord = false
end
end
end
function events()
event, p1 = os.pullEvent()
if event == "key" and
p1 == 208 then
num = num - 1
if num < 1 then
num = 1
end
elseif p1 == 200 then
num = num + 1
if num > 2000 then
num = 2000
end
elseif p1 == 28 then
inPre = false
game()
end
end
function menuEvents()
event, p1 = os.pullEvent()
if event == "key" and
p1 == 208 then
menuStat = menuStat + 1
if menuStat > 4 then
menuStat = 4
end
elseif p1 == 200 then
menuStat = menuStat - 1
if menuStat < 1 then
menuStat = 1
end
elseif p1 == 28 then
inMenu = false
if menuStat == 1 then
--Single Player
preGame()
elseif menuStat == 2 then
--Multiplayer
preGame()
elseif menuStat == 3 then
credits()
elseif menuStat == 4 then
--Exit
cleanScreen()
end
end
end
function drawMenu()
term.clear()
term.setCursorPos(1,1)
term.setCursorPos(1,3)
print("Words ["..num.."]")
print("")
print("Press [Enter] to continue")
end
function drawMenuArt()
local mArt = {
"+------------------------------------------------+",
"|:::::::::::::::+----Typer----+::::::::::::::::::|",
"+------------------------------------------------+",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"| |",
"+------------------------------------------------+",
}
local mOptions = {
"Single Player", "Multiplayer", "Credits", "Exit",
}
for i = 1, #mArt do
drawAt(1,i,mArt[i])
end
for i = 1,#mOptions do
drawAt(4,i + 4,mOptions[i])
end
drawAt(2,4 + menuStat,">")
end
function credits()
inCredits = true
yCrdPos = 10
scrollBar = 4
while inCredits do
cleanScreen()
drawCredits()
drawExtra()
cEvents()
end
end
--CREDITS
function cEvents()
event, p1 = os.pullEvent()
if event == "key" and
p1 == 28 then
inCredits = false
cleanScreen()
elseif p1 == 200 then
yCrdPos = yCrdPos + 1
scrollBar = scrollBar - 0.5
if scrollBar < 4 then
scrollBar = 4
yCrdPos = 10
end
elseif p1 == 208 then
yCrdPos = yCrdPos - 1
scrollBar = scrollBar + 0.5
if scrollBar > 17 then
scrollBar = 17
yCrdPos = yCrdPos + 1
end
end
end
function drawExtra()
drawAt(1,1,"+-------------------------------------------------+")
drawAt(1,2,"| +--CREDITS--+ |")
drawAt(1,3,"|-------------------------------------------------|")
drawAt(1,18,"+-------------------------------------------------+")
drawAt(1,19," --PRESS [ENTER] TO EXIT-- ")
end
function drawCredits()
creditsMenuArt = {
"+-------------------------------------------------+",
"| +--CREDITS--+ |",
"|-------------------------------------------------|",
"| | |",
"| | |",
"| | |",
"| | |",
"| | |",
"| | |",
"| | |",
"| | |",
"| | |",
"| | |",
"| | |",
"| | |",
"| | |",
"| | |",
"+-------------------------------------------------+",
" --PRESS [ENTER] TO EXIT-- ",
}
creditsMenuArtCol = {
" ",
" +--CREDITS--+ ",
" ",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
" | |",
"+-------------------------------------------------+",
" --PRESS [ENTER] TO EXIT-- ",
}
for i = 1, #creditsMenuArt do
drawAt(1,i,creditsMenuArt[i])
drawAt(50,scrollBar,"=")
drawAt(20,yCrdPos - 3,"Typer 2013(c)")
drawAt(18,yCrdPos,"Author: Hellkid98")
drawAt(19,yCrdPos + 3,"+-Programmers-+")
drawAt(22,yCrdPos + 4,"Hellkid98")
end
end
function preGame()
fails = 0
num = 1
inPre = true
while inPre do
drawMenu()
events()
end
end
function main()
menuStat = 1
inMenu = true
while inMenu do
cleanScreen()
drawMenuArt()
menuEvents()
end
end
main()
Spoiler
Or do this————-
pastebin get B2A21J5z typer