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

QuickType - A Minigame

Started by metron80, 01 November 2014 - 09:25 PM
metron80 #1
Posted 01 November 2014 - 10:25 PM
QuickType v1.1.1


What it is:

This program is a mini-game. A randomly generated 6 letter word will appear on screen, and you have a certain amount of time (specified by the user) to type it in. If correct, the time gets shorter, and you do it again! It has 3 difficulties. Easy, hard, and Insane. (More details in features section).

How to use it:

Just copy the text below, paste it into the terminal, and run it! It will handle creating the files it needs.

Features:

Three difficulties:
  • Easy: Not case-sensitive. Only Letters. Just copy!
  • Hard: Case-sensitive. Only letters.
  • Insane: Case-sensitive. Letters, numbers, symbols. Good luck!
Easy to add symbols to difficulties. Just look for this part:
Spoiler

function easyQuestion()
	local letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}
	local question = {letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)],	 letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)]}
	return question[1]..question[2]..question[3]..question[4]..question[5]..question[6]
end
function hardQuestion()
	local letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}
	local question = {letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)],	 letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)]}
	return question[1]..question[2]..question[3]..question[4]..question[5]..question[6]
end
function insaneQuestion()
	local letters = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", ":", "{", "}", "[", "]", "!", "@", "#", "$", "%", "%", "^", "&", "*", "(", ")", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "/", "\\"}
	local question = {letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)],	 letters[math.random(1, #letters)], letters[math.random(1, #letters)], letters[math.random(1, #letters)]}
	return question[1]..question[2]..question[3]..question[4]..question[5]..question[6]
end
Then just add/change/remove stuff in the arrays! Starts at line 59.

Known bugs:

SpoilerNo known bugs! Yay!

Changelog:

Spoilerv1.0
  • Release!
v1.1
  • Minor bug fix with parallel functions.
  • Changed directory making command.
v1.1.1
  • Fixed VERY minor issue making the pastebin herder to read.

Download:

pastebin get AH002ptP quicktype

http://pastebin.com/AH002ptP


Please report any bugs or suggestions in this thread and I will do my best to accommodate you. Thank you and enjoy QuickType!
Edited on 03 November 2014 - 10:56 PM
Saldor010 #2
Posted 02 November 2014 - 01:30 AM
I started playing easy mode, I purposefully misspelled a word to leave, it said "You lost!" and took me back to main menu. Then, a couple of seconds into the main menu, it blurted out "Time is up! You lost!" Then went back to the main menu. Might want to look into that, even if it isn't a game breaking bug.
metron80 #3
Posted 02 November 2014 - 01:52 AM
I started playing easy mode, I purposefully misspelled a word to leave, it said "You lost!" and took me back to main menu. Then, a couple of seconds into the main menu, it blurted out "Time is up! You lost!" Then went back to the main menu. Might want to look into that, even if it isn't a game breaking bug.

Ya… It is a problem with parallel.waitForAny. it is supposed to terminate the second function when the first stops, but it doesn't. I'm looking into a way to fix it.
Dragon53535 #4
Posted 02 November 2014 - 01:56 AM
Real quick tip instead of using shell.run("mkdir CCQT") You could use fs.makeDir("CCQT") which allows you to use it when you don't have access to shell :P/>

Gonna update this post if i can find a way to stop your bug

Noticed something while reading your code, instead of when someone inputs something that you don't allow, there are two things you could do, one turn it into an os.pullEvent instead of read, or put a repeat loop in so that they don't keep trying to crash your system as eventually your code will crash.

These are in your start() function
Example1 repeat on io.read

		local gtype
		repeat --#loop through this code
		  clear()
		  print("			 <[[[QuickType]]]>	 High Score: "..hs)
		  print("		   Choose your Gamemode:")
		  print("")
		  print("				Easy (e)")
		  print("				Hard (h)")
		  print("			   Insane (i)")
		  print("			  More Info (m)")
		  print("				Exit (ex)")
		  print("")
		  io.write("				> ")
		  gamemode = string.lower(io.read())
	  
		  if gamemode == "e" then
				  gtype = "easy"
	  
		  elseif gamemode == "h" then
				  gtype = "hard"
			  
		  elseif gamemode == "i" then
				  gtype = "insane"
			  
		  elseif gamemode == "ex" then
				  print("Goodbye!")
				  sleep(2)
				  clear()
				  error()
			  
		  elseif gamemode == "m" then
				  moreInfo()
			  
		  else
				  print("Invalid Answer")
				  sleep(1) --#Notice the lack of calling start()
		  end
		until gtype ~= nil --#whenever someone actually inputs something and a mode is set, you can easily see if it's nil
Example2 os.pullEvent

		local gtype
		clear()
		print("			 <[[[QuickType]]]>	 High Score: "..hs)
		print("		   Choose your Gamemode:")
		print("")
		print("				Easy (e)")
		print("				Hard (h)")
		print("			   Insane (i)")
		print("			  More Info (m)")
		print("				Exit (x)")
		repeat --#Using another repeat as no text will appear on screen, so i'm putting it here.
		  local event, gamemode = os.pullEvent("char")
	  
		  if gamemode == "e" then
				  gtype = "easy"
	  
		  elseif gamemode == "h" then
				gtype = "hard"
			  
		  elseif gamemode == "i" then
				  gtype = "insane"
			  
		  elseif gamemode == "x" then
				  print("Goodbye!")
				  sleep(2)
				  clear()
				  error()
			  
		  elseif gamemode == "m" then
				  moreInfo()
		  end
		until gtype ~= nil

Found your problem, whenever a user incorrectly enters a word you call start() which means that the game's function still is going on, it's just waiting for start() to end. Eventually that gets killed because the timer goes off and so parallel.waitForAny does what it should be doing, all you need to do instead is just instead of start() in your game functions put return
Edited on 02 November 2014 - 01:11 AM
metron80 #5
Posted 02 November 2014 - 03:08 AM
Real quick tip instead of using shell.run("mkdir CCQT") You could use fs.makeDir("CCQT") which allows you to use it when you don't have access to shell :P/>

Gonna update this post if i can find a way to stop your bug

Noticed something while reading your code, instead of when someone inputs something that you don't allow, there are two things you could do, one turn it into an os.pullEvent instead of read, or put a repeat loop in so that they don't keep trying to crash your system as eventually your code will crash.

These are in your start() function
Example1 repeat on io.read

		local gtype
		repeat --#loop through this code
		  clear()
		  print("			 <[[[QuickType]]]>	 High Score: "..hs)
		  print("		   Choose your Gamemode:")
		  print("")
		  print("				Easy (e)")
		  print("				Hard (h)")
		  print("			   Insane (i)")
		  print("			  More Info (m)")
		  print("				Exit (ex)")
		  print("")
		  io.write("				> ")
		  gamemode = string.lower(io.read())
	  
		  if gamemode == "e" then
				  gtype = "easy"
	  
		  elseif gamemode == "h" then
				  gtype = "hard"
			  
		  elseif gamemode == "i" then
				  gtype = "insane"
			  
		  elseif gamemode == "ex" then
				  print("Goodbye!")
				  sleep(2)
				  clear()
				  error()
			  
		  elseif gamemode == "m" then
				  moreInfo()
			  
		  else
				  print("Invalid Answer")
				  sleep(1) --#Notice the lack of calling start()
		  end
		until gtype ~= nil --#whenever someone actually inputs something and a mode is set, you can easily see if it's nil
Example2 os.pullEvent

		local gtype
		clear()
		print("			 <[[[QuickType]]]>	 High Score: "..hs)
		print("		   Choose your Gamemode:")
		print("")
		print("				Easy (e)")
		print("				Hard (h)")
		print("			   Insane (i)")
		print("			  More Info (m)")
		print("				Exit (x)")
		repeat --#Using another repeat as no text will appear on screen, so i'm putting it here.
		  local event, gamemode = os.pullEvent("char")
	  
		  if gamemode == "e" then
				  gtype = "easy"
	  
		  elseif gamemode == "h" then
				gtype = "hard"
			  
		  elseif gamemode == "i" then
				  gtype = "insane"
			  
		  elseif gamemode == "x" then
				  print("Goodbye!")
				  sleep(2)
				  clear()
				  error()
			  
		  elseif gamemode == "m" then
				  moreInfo()
		  end
		until gtype ~= nil

Found your problem, whenever a user incorrectly enters a word you call start() which means that the game's function still is going on, it's just waiting for start() to end. Eventually that gets killed because the timer goes off and so parallel.waitForAny does what it should be doing, all you need to do instead is just instead of start() in your game functions put return

Thanks. I will fix those.
Edit1: Fixed! v1.1

Edit2: Quick question: Anyone know why on pastebin, it identifies half the text as a comment, and the other half as a string, even though the highlighting syntax is Lua?
Edited on 02 November 2014 - 02:18 AM
InputUsername #6
Posted 03 November 2014 - 04:27 PM


Edit2: Quick question: Anyone know why on pastebin, it identifies half the text as a comment, and the other half as a string, even though the highlighting syntax is Lua?

Probably because the highlighting software Pastebin uses doesn't recognise the –]] you used to terminate the comment as a correct comment terminator.
metron80 #7
Posted 03 November 2014 - 11:55 PM
Might as well make the pastebin easier to read. v1.1.1!