When I select two items for the mixing process and click on "Start mixing" a function is called (MixItems)which checks if there is any combination between the two.
If there is, then a new item is added to the inventory while both used items are removed .
But I also want to reset variables that define which item is selected as "mix1", "mix2", selected_item
Check this:
Code: Select all
init python:
class Item:
def __init__(self, name, img, hover_img):
self.name = name
self.img = img
self.hover_img = hover_img
def addItem(theitem):
inventory.append(theitem)
def MixItems():
if mix1 == iScissors:
if mix2 == iHair:
inventory.append(iEye)
inventory.remove(iHair)
inventory.remove(iScissors)
mix1 = None
mix2 = None
selected_item = None
def MInv():
mix1 = None
mix2 = None
selected_item = None
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 52, in script
"Halo"
File "renpy/common/00action_other.rpy", line 537, in __call__
rv = self.callable(*self.args, **self.kwargs)
File "game/inventory_screen.rpy", line 20, in MixItems
if mix1 == iScissors:
UnboundLocalError: local variable 'mix1' referenced before assignment
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 52, in script
"Halo"
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\ast.py", line 708, in execute
renpy.exports.say(who, what, *args, **kwargs)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\exports.py", line 1345, in say
who(what, *args, **kwargs)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\character.py", line 1142, in __call__
self.do_display(who, what, cb_args=self.cb_args, **display_args)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\character.py", line 842, in do_display
**display_args)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\character.py", line 591, in display_say
rv = renpy.ui.interact(mouse='say', type=type, roll_forward=roll_forward)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\ui.py", line 297, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\core.py", line 2702, in interact
repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\core.py", line 3518, in interact_core
rv = root_widget.event(ev, x, y, 0)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\layout.py", line 998, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\layout.py", line 998, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\layout.py", line 998, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\screen.py", line 714, in event
rv = self.child.event(ev, x, y, st)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\layout.py", line 998, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\layout.py", line 998, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\layout.py", line 998, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\layout.py", line 244, in event
rv = d.event(ev, x - xo, y - yo, st)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\layout.py", line 998, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\behavior.py", line 962, in event
return handle_click(self.clicked)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\behavior.py", line 897, in handle_click
rv = run(action)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\behavior.py", line 313, in run
new_rv = run(i, *args, **kwargs)
File "C:\Users\Business laptop\Downloads\Programs\renpy-7.3.5-sdk\renpy\display\behavior.py", line 320, in run
return action(*args, **kwargs)
File "renpy/common/00action_other.rpy", line 537, in __call__
rv = self.callable(*self.args, **self.kwargs)
File "game/inventory_screen.rpy", line 20, in MixItems
if mix1 == iScissors:
UnboundLocalError: local variable 'mix1' referenced before assignment
Windows-8-6.2.9200
Ren'Py 7.3.5.606
inventory tst 5 1.0
Wed Jan 22 13:05:44 2020
Code: Select all
def MixItems():
if mix1 == iScissors:
if mix2 == iHair:
inventory.append(iEye)
inventory.remove(iHair)
inventory.remove(iScissors)
MInv
def MInv():
mix1 = None
mix2 = None
selected_item = None
I appreciate any help.