So I'm making a text based rpg, and I'm trying to make a in battle menu for using magic spells.
Since I want the player to type the name of spells he wishes to use, I made spell an input. After that, I wish that depending on the spell name the player types, something happens (the spell, of course). So I've set some spells (8-9), but apparently only the first is ok, because starting from the second, every other spell coded points to a SyntaxError, and I don't get why!
Here's the code:
def magic():
os.system("cls")
print("These are the spells you can use:")
print(player_ig.spells)
if player_ig.speed>=enemy.speed:
print("\nType the name of the spell you wish to cast or enter 1 to go back.")
print("1.)Back")
spell=input("-->")
global spell
else:
print("\nType the name of the spell you wish to cast.")
spell=input("-->")
global spell
if spell=="1" and player_ig.speed>=enemy.speed:
fight()
if spell=="Energy Bolt":
if player_ig.magic%2==0:
magic_dam= random.randint(player_ig.magic/2, player_ig.magic+1)
else:
magic_dam= random.randint((player_ig.magic+1)/2, player_ig.magic+1)
if magic_dam==player_ig.magic/2 or player_ig.magic%2!=0 and magic_dam==(player_ig.magic+1)/2 :
print("You miss!")
option=input("-->")
else:
enemy.health-=magic_dam-enemy.magic
print("Your %s deal %i magic damage to your oponent"%(spell,magic_dam-enemy.magic)
elif spell=="Summon Familiar":
#code for the spell
elif spell=="Fire":
#code for the spell
and when I run it I get Syntax error on elif spell=="Summon Familiar":, like so: Syntax error
Even if change elif for if, like it's written for "Energy Bolt", it will give me the same error. What is wrong with my code? Shouldn't I be using elif there? Why it is working for "Energy Bolt" but not for the others?
Sorry if the answer is simple or something, I am new to python and programming in general...
Aucun commentaire:
Enregistrer un commentaire