Okays, so I've read through both your advices and this is what I have came to put together hahahah:
Code: Select all
init 1:
default item = 0
default use_item = 0
default inventory = {
'Blue Gem': {"idle":"images/inventory/gem_blue.png", "selected":"images/inventory/gem_blue_selected.png", "title":"Water", "description":"A blue gem"},
'Red Gem': {"idle":"images/inventory/gem_red.png", "selected":"images/inventory/gem_red_selected.png", "title":"Fire", "description":"A red gem"},
'Green Gem': {"idle":"images/inventory/gem_green.png", "selected":"images/inventory/gem_green_selected.png", "title":"Land", "description":"A green gem"},
}
$ use_item = []
$ hp_integer = 100
$ ma_integer = 100
$ hp = "%d" % hp_integer
$ ma = "%d" % ma_integer
init python:
def use_item():
if use_item["hp"]: #healing item
hp_integer = hp_integer+use_item["hp"]
if hp_integer > 100: # can't heal beyond max HP
hp_integer = 100
#inventory.drop(self) # consumable item - drop after use
elif use_item["ma"]: #mp restore item
ma_integer = ma_integer+use_item["ma"]
if ma_integer > 100: # can't increase MP beyond max MP
ma_integer = 100
#inventory.drop(self) # consumable item - drop after use
else:
null
screen description(desc):
vbox:
text desc
xpos 660
ypos 530
screen inventory:
tag menu
imagemap:
ground "gui/inventory_background.png"
hover "gui/inventory_hover_background.png"
selected_idle "gui/inventory_background.png"
selected_hover "gui/inventory_hover_background.png"
alpha False
hotspot (1170, 0, 110, 140) action [Return(), Hide("itemmenu")]
#hotspot (982, 546, 115, 44) action Function(use_item)
#hotspot (982, 586, 115, 44) action inventory.pop(use_item)
vbox:
text hp
xpos 660
ypos 560
vbox:
text ma
xpos 660
ypos 590
grid 4 2:
spacing 16
xpos 652
ypos 230
for key, item in inventory.items():
imagebutton:
xsize 73
ysize 71
idle item["idle"]
selected use_item == item
selected_idle item["selected"]
selected_hover item["selected"]
hovered Show("description", desc=item["description"])
unhovered Hide("description")
action [Show("itemmenu", title=item["title"]), SetVariable("use_item", key)]
for i in range(8 - len(inventory)):
null
screen itemmenu(title):
vbox:
text title
xpos 660
ypos 530
I would have been open to read through and better understand how lists and dictionaries work with python, but I'm kinda in a rush to get this out by a deadline I have. So I'll cut to the point of my questions:
1- currently the above code works just fine (no crashes), but the items' selected images are gone, it's still hoverable and clickable but it just displays the idle image, my guess is...
is somehow overwriting
and
? I've tried placing the first line of code above and below the other 2, doesn't seem to make a difference.
---
2- what I would need to happen for the below code is have the user select an object, then if the "remove" button is pressed, the object will be removed from the inventory.
Code: Select all
#hotspot (982, 586, 115, 44) action inventory.pop(use_item)
but right now, if I use this code, the following error will appear:
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/screens.rpy", line 219, in execute
screen inventory:
File "game/screens.rpy", line 219, in execute
screen inventory:
File "game/screens.rpy", line 222, in execute
imagemap:
File "game/screens.rpy", line 231, in execute
hotspot (982, 586, 115, 44) action inventory.pop(use_item)
File "game/screens.rpy", line 231, in keywords
hotspot (982, 586, 115, 44) action inventory.pop(use_item)
KeyError: 0
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script
python hide:
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/ast.py", line 814, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/python.py", line 1719, in py_exec_bytecode
exec bytecode in globals, locals
File "renpy/common/_layout/screen_main_menu.rpym", line 30, in <module>
ui.interact()
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/ui.py", line 285, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/core.py", line 2526, in interact
repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/core.py", line 2793, in interact_core
root_widget.visit_all(lambda i : i.per_interact())
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/core.py", line 495, in visit_all
d.visit_all(callback)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/core.py", line 495, in visit_all
d.visit_all(callback)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/core.py", line 495, in visit_all
d.visit_all(callback)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/screen.py", line 399, in visit_all
callback(self)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/core.py", line 2793, in <lambda>
root_widget.visit_all(lambda i : i.per_interact())
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/screen.py", line 409, in per_interact
self.update()
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/screen.py", line 578, in update
self.screen.function(**self.scope)
File "game/screens.rpy", line 219, in execute
screen inventory:
File "game/screens.rpy", line 219, in execute
screen inventory:
File "game/screens.rpy", line 222, in execute
imagemap:
File "game/screens.rpy", line 231, in execute
hotspot (982, 586, 115, 44) action inventory.pop(use_item)
File "game/screens.rpy", line 231, in keywords
hotspot (982, 586, 115, 44) action inventory.pop(use_item)
File "<screen language>", line 231, in <module>
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/python.py", line 618, in do_mutation
return method(self, *args, **kwargs)
KeyError: 0
Darwin-17.4.0-x86_64-i386-64bit
Ren'Py 6.99.12.4.2187
---
3- the below code should allow the user to "use" and item when the hotspot is pressed after selecting an item.
Code: Select all
#hotspot (982, 546, 115, 44) action Function(use_item)
so if the item is used, the code will check for the action required to be taken, say -50ma or +50hp.
Code: Select all
def use_item():
if use_item["hp"]:
hp_integer = hp_integer+use_item["hp"]
if hp_integer > 100:
hp_integer = 100
elif use_item["ma"]:
ma_integer = ma_integer+use_item["ma"]
if ma_integer > 100:
ma_integer = 100
else:
null
but currently, if pressed, this error will appear:
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "renpy/common/00action_other.rpy", line 484, in __call__
rv = self.callable(*self.args, **self.kwargs)
TypeError: 'unicode' object is not callable
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "renpy/common/_layout/screen_main_menu.rpym", line 28, in script
python hide:
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/ast.py", line 814, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/python.py", line 1719, in py_exec_bytecode
exec bytecode in globals, locals
File "renpy/common/_layout/screen_main_menu.rpym", line 30, in <module>
ui.interact()
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/ui.py", line 285, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/core.py", line 2526, in interact
repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/core.py", line 3204, in interact_core
rv = root_widget.event(ev, x, y, 0)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/layout.py", line 960, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/layout.py", line 960, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/layout.py", line 960, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/screen.py", line 651, in event
rv = self.child.event(ev, x, y, st)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/layout.py", line 960, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/layout.py", line 960, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/layout.py", line 960, in event
rv = i.event(ev, x - xo, y - yo, cst)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/behavior.py", line 889, in event
return handle_click(self.clicked)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/behavior.py", line 824, in handle_click
rv = run(action)
File "/Volumes/OTHERS/VN/RenPy/renpy-6.99.11-sdk/renpy/display/behavior.py", line 306, in run
return action(*args, **kwargs)
File "renpy/common/00action_other.rpy", line 484, in __call__
rv = self.callable(*self.args, **self.kwargs)
TypeError: 'unicode' object is not callable
Darwin-17.4.0-x86_64-i386-64bit
Ren'Py 6.99.12.4.2187