fork(1) download
  1. -- your code goes here
  2. local function battle() -- All of this is 100% unfinished, by the way
  3. n = math.random(10) + 1 -- Everybody's HP, enemy HP randomly generated number from 10 to 100
  4. enemyhp = 10*n
  5. herohp = 100
  6. io.write("Your HP: ")
  7. io.write(herohp)
  8. io.write(" ")
  9. io.flush()
  10. io.write("Enemy HP: ")
  11. io.write(enemyhp)
  12. io.write(" ")
  13. io.flush()
  14. if enemyhp <= 0 then
  15. print("You won!")
  16. end
  17. end
  18. local function attack() -- Attacking the enemy or running away
  19. print("|Attack|Flee|")
  20. input = io.read()
  21. if input == "attack" then -- This is where my error is
  22. attackdamage = math.random(51)
  23. if attackdamage == 51 then
  24. print("Critical Hit!")
  25. enemyhp = enemyhp - 100
  26. else
  27. enemyhp = enemyhp - attackdamage
  28. print("Enemy took ")
  29. io.write(attackdamage)
  30. io.write(" damage!")
  31. end
  32. elseif input == "flee" then
  33. print("You ran away!")
  34. end
  35. end
Success #stdin #stdout 0s 2784KB
stdin
Standard input is empty
stdout
Standard output is empty