2 posts
Posted 20 January 2014 - 01:26 PM
I am writing the battling mechanic of a text based rpg, and I have almost completed it. My issue is as follows.
When running the program, I get the message:
'bios:338: [string "battle"]:203: 'end' expected (to close 'function at line 61)'
After locating line 203, it appears that computercraft is telling me to replace a key part of the code with 'end'
Here are lines 195-209 which cover the conditional statement in which this problem seems to occur.
Please tell me if you require more, or all of my code (it is rather long)
ans5 = read()
if ans5 == "N" then
os.reboot()
end
elseif ans5 == "Shop" then
print"Going to shop"
Shop()
end
elseif ans5 == "Y" then –Starts new battle
print"Starting new battle…"
sleep(2)
print"Finding opponent…"
sleep(2)
print"Assigning Values…"
sleep(2)
2 posts
Posted 20 January 2014 - 01:41 PM
I am making a text based rpg (I am only making the battle system at the moment).
My issue is that when I type help (when it gives the option Y/N/SHOP) it just stops the program and fails to run the Shop() function.
Here is the code (There is a rather large amount of it):
term.clear()
PH = 30 –Player Health
Money = 0 –Amount of money
Name = Nick –Name of character
Monster = "none" –Name of Monster
MH = 0 –Monster Health
MD = 0 –Monster Damage
HealthPot = 0 –Number of Health Potions that the player has
Shop = function()
term.clear()
print"Welcome to the BattleQuest shop. What can I get yer?"
print"Health Potion"
ans4 = read()
if ans4 == "Health Potion" then
if Money>12 then
HealthPot = HealthPot+1
Money = Money-12
print"You bought 1 of item: Health Potion!"
print"Returning to shop…"
sleep(1)
Shop()
else
print"Sorry, yer don't have enough money for that!"
end
elseif ans4 == "Leave" then
print"Entering battle…"
sleep(1)
battle()
else
print"Sorry, I didn't catch that. What did yer say?"
end
end
Name = function()
print"What is your name?"
Name = read()
write(Name)
write", what a cool name!\n"
end
continue = function()
print"Begin your adventure?"
print"Y/N"
ans = read()
if ans == "Y" then
battle()
elseif ans == "N" then
print"Oh. Ok. I'll see you next time I guess"
term.reboot()
else
print"ERROR:Please answer using options."
continue()
end
end
BattleInitiate = function()
MH = math.random(15,30)
while MH>0
do
if PH<=0 then
write(Name)
write" is dead!"
write"\n"
print"GAME OVER"
sleep(3)
os.reboot()
end
write"You have "
write(HealthPot)
write" health potion(s) left"
write"\n"
MD = math.random(1,6)
write"The "
write(Monster)
write" deals "
write(MD)
write" on you\n"
PH = PH-MD
write"Your health is: "
write(PH)
write"\n"
print"Choose attack style" –User chooses how to attack
print"Stab/Slash" –Stab(Guaranteed to hit, but lower damage) Slash(Less likely to hit but high damage)
Style = read()
if Style == "Stab" then
D = math.random(1,10)
write"You hit "
write(D)
write" on the "
write(Monster)
write"\n"
MH = MH-D
write"The "
write(Monster)
write"'s health is now: "
write(MH)
write"\n"
elseif Style == "Slash" then
X = math.random(1,3) –Whether or not you even hit the opponent
if X == 1 then
write"You miss the "
write(Monster)
write"!\n"
elseif X == 2 then
D = math.random(5,20)
write"You hit "
write(D)
write" on the "
write(Monster)
write"\n"
MH = MH-D
write"The "
write(Monster)
write"'s health is now: "
write(MH)
write"\n"
elseif X == 3 then
D = math.random(5,20)
write"You hit "
write(D)
write" on the "
write(Monster)
write"\n"
MH = MH-D
write"The "
write(Monster)
write"'s health is now: "
write(MH)
write"\n"
end
end
end
if MH<=0 then
write(Monster)
write" has been defeated!\n"
print"Would you like to loot it?"
print"Y/N"
ans2 = read()
if ans2 == "Y" then
loot1 = math.random(1,15)
Money = Money+loot1
write"The "
write(Monster)
write" had "
write(loot1)
write" coin(s)!\n"
write"You now have "
write(Money)
write" coins in your money pouch!\n"
print"Would you like to fight another monster?"
print"Or would you like to visit the shop?"
print"Y/N/SHOP"
ans3 = read()
if ans3 == "Y" then –Starts new battle
print"Starting new battle…"
sleep(2)
print"Finding opponent…"
sleep(2)
print"Assigning Values…"
sleep(2)
A = math.random(1,3)
if A == 1 then
print"A bloodthirsty wolf jumps out at you"
Monster = "Wolf"
BattleInitiate()
elseif A == 2 then
print"A giant spider crawls lowers itself in front of you"
Monster = "Spider"
BattleInitiate()
elseif A == 3 then
print"A slimy worm slivers towards you"
Monster = "Worm"
BattleInitiate()
end
end
elseif ans3 == "N" then
os.reboot()
elseif ans3 == "Shop" then
print"Going to shop"
Shop()
end
elseif ans2 == "N" then
write"You leave the "
write(Monster)
write" and move on\n"
print"Would you like to fight another monster?"
print"Or would you like to visit the shop?"
print"Y/N/Shop"
ans5 = read()
if ans5 == "N" then
os.reboot()
end
elseif ans5 == "Shop" then
print"Going to shop"
Shop() <——————–This is where the problem is!
elseif ans5 == "Y" then –Starts new battle
print"Starting new battle…"
sleep(2)
print"Finding opponent…"
sleep(2)
print"Assigning Values…"
sleep(2)
A = math.random(1,3)
if A == 1 then
print"A bloodthirsty wolf jumps out at you"
Monster = "Wolf"
BattleInitiate()
elseif A == 2 then
print"A giant spider crawls lowers itself in front of you"
Monster = "Spider"
BattleInitiate()
elseif A == 3 then
print"A slimy worm slivers towards you"
Monster = "Worm"
BattleInitiate()
end
end
end
battle = function()
A = math.random(1,3)
if A == 1 then
print"A bloodthirsty wolf jumps out at you"
Monster = "Wolf"
BattleInitiate()
elseif A == 2 then
print"A giant spider crawls lowers itself in front of you"
Monster = "Spider"
BattleInitiate()
elseif A == 3 then
print"A slimy worm slivers towards you"
Monster = "Worm"
BattleInitiate()
end
end
Name()
continue()
8543 posts
Posted 20 January 2014 - 02:54 PM
Since these topics involve the same piece of code, I've merged them.
60 posts
Posted 20 January 2014 - 05:51 PM
If you want us to help you properly, a good start would be to put your code in code tags, put that in spoiler tags and indent your code. You'll find any faulty or missing ends that way as well.