Advertisement
minimite

funnycalc

Nov 24th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.70 KB | None | 0 0
  1. --FunnyCalc, a "fake" calculator
  2. --By CodedPixelCube, aka Minimite, for ComputerCraft, a Minecraft mod that adds computers
  3.  
  4. term.clear()
  5. term.setCursorPos(1,1)
  6.  
  7. function execute(executeCode)
  8. --name of the file, if you use error command it will show this file
  9. local defFile = "calcemulator"
  10.  
  11. --open and write the code they want inside the file
  12. local open = fs.open(defFile, "w")
  13. open.write(executeCode)
  14. open.close()
  15. --run the file
  16. shell.run(defFile)
  17. --sleep for a little just in case something breaks
  18. sleep(0)
  19. --delete the file, we don't need it anymore
  20. fs.delete(defFile)
  21. end
  22.  
  23. while true do
  24. local input = read()
  25. local input = input:gsub(" ","")
  26. --stupid things you can also put in
  27. if input == "meaningoflife,theuniverse,andeverything" then
  28. print("42")
  29. elseif input == "9+10" then
  30. print("21")
  31. elseif input == "9 + 10" then
  32. print("21")
  33. elseif input == "exit" then
  34. return
  35. elseif input == "Bornholm" then --bornholm is a danish island
  36. print("588 square kilometers")
  37. elseif input == "cake" then
  38. print("Yummy!")
  39. elseif input == "fire" then
  40. print("BEEEE DOOOOO BEEEEE DOOOOOO BEEEEE DOOOO BEEEEEE DOOOOOOO")
  41. sleep(1)
  42. term.clear()
  43. term.setCursorPos(1,1)
  44.  
  45.  
  46. --part to go back toe xecuting code
  47. elseif string.find(input, "execute") then
  48.  
  49. local codetoexecute = input:gsub("execute","")
  50. execute(codetoexecute)
  51.  
  52.  
  53. else
  54. --get the input with only the digits
  55. local inputclean = input:gsub("%D","")
  56.  
  57. --if no numbers
  58. if inputclean == "" then
  59. elseif inputclean == " " then
  60. elseif inputclean == nil then
  61. else
  62. --if yes numbers, set the random seed to the
  63. --input with only digits
  64. math.randomseed(inputclean)
  65. --pick a random number 1,50 depending on randomseed
  66. print(math.random(1,50))
  67. end
  68.  
  69. end
  70.  
  71. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement