-- your code goes here
local function battle() -- All of this is 100% unfinished, by the way
n = math.random(10) + 1 -- Everybody's HP, enemy HP randomly generated number from 10 to 100
enemyhp = 10*n
herohp = 100
io.write("Your HP: ")
io.write(herohp)
io.write(" ")
io.flush()
io.write("Enemy HP: ")
io.write(enemyhp)
io.write(" ")
io.flush()
if enemyhp <= 0 then
print("You won!")
end
end
local function attack() -- Attacking the enemy or running away
print("|Attack|Flee|")
input = io.read()
if input == "attack" then -- This is where my error is
attackdamage = math.random(51)
if attackdamage == 51 then
print("Critical Hit!")
enemyhp = enemyhp - 100
else
enemyhp = enemyhp - attackdamage
print("Enemy took ")
io.write(attackdamage)
io.write(" damage!")
end
elseif input == "flee" then
print("You ran away!")
end
end
LS0geW91ciBjb2RlIGdvZXMgaGVyZQpsb2NhbCBmdW5jdGlvbiBiYXR0bGUoKSAtLSBBbGwgb2YgdGhpcyBpcyAxMDAlIHVuZmluaXNoZWQsIGJ5IHRoZSB3YXkKICBuID0gbWF0aC5yYW5kb20oMTApICsgMSAtLSBFdmVyeWJvZHkncyBIUCwgZW5lbXkgSFAgcmFuZG9tbHkgZ2VuZXJhdGVkIG51bWJlciBmcm9tIDEwIHRvIDEwMAogIGVuZW15aHAgPSAxMCpuCiAgaGVyb2hwID0gMTAwCiAgaW8ud3JpdGUoIllvdXIgSFA6ICIpCiAgaW8ud3JpdGUoaGVyb2hwKQogIGlvLndyaXRlKCIgIikKICBpby5mbHVzaCgpCiAgaW8ud3JpdGUoIkVuZW15IEhQOiAiKQogIGlvLndyaXRlKGVuZW15aHApCiAgaW8ud3JpdGUoIiAiKQogIGlvLmZsdXNoKCkKICBpZiBlbmVteWhwIDw9IDAgdGhlbgogICAgcHJpbnQoIllvdSB3b24hIikKICBlbmQKZW5kCmxvY2FsIGZ1bmN0aW9uIGF0dGFjaygpICAtLSBBdHRhY2tpbmcgdGhlIGVuZW15IG9yIHJ1bm5pbmcgYXdheQogIHByaW50KCJ8QXR0YWNrfEZsZWV8IikKICBpbnB1dC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