Posted 22 July 2015 - 11:05 PM
Before you post something like "it means you didn't close a while statement" or something like that, please read this.
I am getting the error, "[string "battle"]:180: 'end' expected to close 'while' at line 128", but i looked through the code, and it looked like all the if, and while statements were closed with an 'end'. I'm likely just missing something, but i seriously don't know where i didn't close something.
It's a work in progress, so there might be more errors that ill be able to fix while im making it. i just need help with this one error right now. Thanks in advance :)/>
Here is my code:
I am getting the error, "[string "battle"]:180: 'end' expected to close 'while' at line 128", but i looked through the code, and it looked like all the if, and while statements were closed with an 'end'. I'm likely just missing something, but i seriously don't know where i didn't close something.
It's a work in progress, so there might be more errors that ill be able to fix while im making it. i just need help with this one error right now. Thanks in advance :)/>
Here is my code:
Spoiler
function reset ()
term.clear()
term.setCursorPos(1,1)
end
function line ()
print("")
end
function printcolor (x,y)
term.setTextColor(y)
print(x)
term.setTextColor(colors.white)
end
x = 0
y = 0
function menu ()
reset()
print("[Battle]")
line()
print("[>] New Game")
print("[>] Load Game")
print("[>] Custom Game")
print("[>] Quit")
line()
print("Click on the icon next to option.")
while true do
local event, button, x, y = os.pullEvent( "mouse_click" )
if x == 2 then
if y == 3 then
newgame()
elseif y == 4 then
loadgame()
elseif y == 5 then
custom()
elseif y == 6 then
reset()
print("Thanks for playing!")
error()
else
menu()
end
end
end
end
function newgame ()
reset()
print("Please Wait...")
maxhp = 100
hp = maxhp
bdmg = 4
dmg = bdmg
bdef = 0
def = bdef
heal = 0
emaxhp = 100
ehp = emaxhp
ebdmg = 4
edmg = ebdmg
ebdef = 0
edef = ebdef
eheal = 0
fs.makeDir("battle_data")
h = fs.open("battle_data/maxhp.dat")
h.write(maxhp)
h.close()
h = fs.open("battle_data/hp.dat")
h.write(hp)
h.close()
h = fs.open("battle_data/dmg.dat")
h.write(dmg)
h.close()
h = fs.open("battle_data/def.dat")
h.write(def)
h.close()
h = fs.open("battle_data/heal.dat")
h.write(heal)
h.close()
h = fs.open("battle_data/emaxhp.dat")
h.write(emaxhp)
h.close()
h = fs.open("battle_data/ehp.dat")
h.write(ehp)
h.close()
h = fs.open("battle_data/ebdmg.dat")
h.write(ebdmg)
h.close()
h = fs.open("battle_data/ebdef.dat")
h.write(ebdef)
h.close()
h = fs.open("battle_data/eheal.dat")
h.write(eheal)
h.close()
game()
end
function game ()
reset()
print("Health: "..hp.."/"..maxhp)
print("Enemy Health: "..ehp.."/"..emaxhp)
print(heal.." Health Potions")
line()
print(desc)
print(desc1)
line()
print("[X] Attack")
print("[^] Raise Attack")
print("[^] Raise Defence")
if heal > 0 then
print("[^] Heal")
else
printcolor("[^] Heal",colors.grey)
end
line()
print("[>] Exit To Menu")
print("[>] Exit")
line()
while turn == 0 do
local event, button, x, y = os.pullEvent( "mouse_click" )
if x == 2 then
if y == 7 then
local xx = ehp-(dmg-edef)
if xx < 1 then xx = 1
ehp = xx
desc = "You attacked the enemy, dealing "..xx.." damage."
turn = 1
elseif y == 8 then
dmg = dmg+1
desc = "You raised your attack."
turn = 1
elseif y == 9 then
def = def+1
desc = "You raised your defence."
turn = 1
elseif (y == 10) and heal > 0 then
hp = hp+10
heal = heal-1
desc = "You recovered 10 health."
turn = 1
end
end
end
if eheal == 0 then
local xx = math.random(0,2)
elseif (eheal ~= 0) and (ehp < emaxhp-10) then
local xx = math.random(0,3)
end
local yy = math.random(1,5)
if xx == 0 then
local xx1 = hp-(edmg-def)
if xx1 < 1 then xx1 = 1
hp = xx1
desc = "The enemy attacked, dealing "..xx1.." damage."
elseif xx == 1 then
edmg = edmg+1
desc = "The enemy raised its attack."
elseif xx == 2 then
edef = edef+1
desc = "The enemy raised its defence."
elseif xx == 3 then
ehp = ehp+10
eheal = eheal-1
desc = "The enemy recovered 10 health."
end
game()
end
menu()
Edited on 22 July 2015 - 09:11 PM