I am trying to rewrite an old GUI-based adventure game of mine and am running into trouble. I am nothing but a humble beginner, so I can't properly diagnose what is going on here. In my code I use and if statement to see if they have the item skull
in their inventory (inv
). Even if inv==skull
, the program continues down to the last else
as if they don't have the skull in their inventory, instead of going to line 64 and seeing that inv==('skull')
.
Any and all help would be greatly appreciated, including those of how to optimize by code, not just fix it :)
Edit: I have began trying to use a list (Tuple) and then checking if the item is in the list, and it still isn't working :(
Edited Code:
inv=['skull']
def r_room():
def witch_fight():
def fgt_slap():
rand = random.randint(1, 13)
if rand <= 12:
slap_die()
else:
slap_win()
def fgt_sh():
rand = random.randint(1, 13)
if rand <= 9:
sh_die()
else:
sh_win()
def fgt_gc():
rand = random.randint(1, 13)
if rand <= 7:
gc_die()
else:
gc_win()
fgt_play()
global inv
if inv in ['skull', 'crest']:
img_loc = ('resources\\images\\witch.gif')
bg_img = tk.PhotoImage(file = img_loc)
bg_lbl = tk.Label(image = bg_img)
bg_lbl.image = bg_img
bg_lbl.place(x=0, y=0)
lbl1 = tk.Label(text='Time to teach this witch who\'s boss!',
fg='#cdd0d0', bg='#000000', font = ['Helvetica', 15])
lbl1.place(x=400, y=6)
btn1 = tk.Button(text='Slap Her?', font = ['Helvetica', 25], bg='#000000', fg='#cdd0d0', width=16,
command = lambda:[btn1.destroy(), btn2.destroy(), btn3.destroy(), lbl1.destroy(), bg_lbl.destroy(), snd_stop(), fgt_slap()])
btn1.place(x=330, y=654)
btn2 = tk.Button(text='Use Skeleton Head?', font = ['Helvetica', 25], bg='#000000', fg='#cdd0d0', width=16,
command = lambda:[btn1.destroy(), btn2.destroy(), btn3.destroy(), lbl1.destroy(), bg_lbl.destroy(), snd_stop(), fgt_sh()])
btn2.place(x=640, y=654)
btn3 = tk.Button(text='Use Golden Crest?', font = ['Helvetica', 25], bg='#000000', fg='#cdd0d0', width=16,
command = lambda:[btn1.destroy(), btn2.destroy(), btn3.destroy(), lbl1.destroy(), bg_lbl.destroy(), snd_stop(), fgt_gc()])
btn3.place(x=950, y=654)
else:
if inv in ['skull']:
img_loc = ('resources\\images\\witch.gif')
bg_img = tk.PhotoImage(file = img_loc)
bg_lbl = tk.Label(image = bg_img)
bg_lbl.image = bg_img
bg_lbl.place(x=0, y=0)
lbl1 = tk.Label(text='Time to teach this witch who\'s boss!',
fg='#cdd0d0', bg='#000000', font = ['Helvetica', 15])
lbl1.place(x=400, y=6)
btn1 = tk.Button(text='Slap Her?', font = ['Helvetica', 25], bg='#000000', fg='#cdd0d0', width=16,
command = lambda:[btn1.destroy(), btn2.destroy(), lbl1.destroy(), bg_lbl.destroy(), snd_stop(), fgt_slap()])
btn1.place(x=330, y=654)
btn2 = tk.Button(text='Use Skeleton Head?', font = ['Helvetica', 25], bg='#000000', fg='#cdd0d0', width=16,
command = lambda:[btn1.destroy(), btn2.destroy(), lbl1.destroy(), bg_lbl.destroy(), snd_stop(), fgt_sh()])
btn2.place(x=640, y=654)
else:
if inv in ['crest']:
img_loc = ('resources\\images\\witch.gif')
bg_img = tk.PhotoImage(file = img_loc)
bg_lbl = tk.Label(image = bg_img)
bg_lbl.image = bg_img
bg_lbl.place(x=0, y=0)
lbl1 = tk.Label(text='Time to teach this witch who\'s boss!',
fg='#cdd0d0', bg='#000000', font = ['Helvetica', 15])
lbl1.place(x=400, y=6)
btn1 = tk.Button(text='Slap Her?', font = ['Helvetica', 25], bg='#000000', fg='#cdd0d0', width=16,
command = lambda:[btn1.destroy(), btn2.destroy(), lbl1.destroy(), bg_lbl.destroy(), snd_stop(), fgt_slap()])
btn1.place(x=330, y=654)
btn2 = tk.Button(text='Use Golden Crest?', font = ['Helvetica', 25], bg='#000000', fg='#cdd0d0', width=16,
command = lambda:[btn1.destroy(), btn2.destroy(), lbl1.destroy(), bg_lbl.destroy(), snd_stop(), fgt_gc()])
btn2.place(x=640, y=654)
else:
img_loc = ('resources\\images\\witch.gif')
bg_img = tk.PhotoImage(file = img_loc)
bg_lbl = tk.Label(image = bg_img)
bg_lbl.image = bg_img
bg_lbl.place(x=0, y=0)
lbl1 = tk.Label(text='Time to teach this witch who\'s boss!',
fg='#cdd0d0', bg='#000000', font = ['Helvetica', 15])
lbl1.place(x=500, y=6)
btn1 = tk.Button(text='Slap Her?', font = ['Helvetica', 25], bg='#000000', fg='#cdd0d0', width=16,
command = lambda:[btn1.destroy(), lbl1.destroy(), bg_lbl.destroy(), snd_stop(), fgt_slap()])
btn1.place(x=480, y=654)