Have a dictionary with all items. For example:
Code: Select all
default itemz = {'sword': {"name": "sword",'img': img_path + "steel_sword_idle.png", "atk":10,"val":20},'helm': {"name": "helm",'img': img_path + "steel_helm_idle.png","atk": 0,"def": 10,"val": 20}}
Code: Select all
screen test_buttons():
for item in itemz:
imagebutton idle [item][img] action SetVariable("selected_item", item) xalign 0.5 yalign 0.5
Code: Select all
Full traceback:
File "game/script.rpy", line 39, in script
File "F:\Renpy\renpy\ast.py", line 706, in execute
renpy.exports.say(who, what, *args, **kwargs)
File "F:\Renpy\renpy\exports.py", line 1336, in say
who(what, *args, **kwargs)
File "F:\Renpy\renpy\character.py", line 1139, in __call__
self.do_display(who, what, cb_args=self.cb_args, **display_args)
File "F:\Renpy\renpy\character.py", line 842, in do_display
**display_args)
File "F:\Renpy\renpy\character.py", line 591, in display_say
rv = renpy.ui.interact(mouse='say', type=type, roll_forward=roll_forward)
File "F:\Renpy\renpy\ui.py", line 295, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "F:\Renpy\renpy\display\core.py", line 2699, in interact
repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, **kwargs)
File "F:\Renpy\renpy\display\core.py", line 3091, in interact_core
root_widget.visit_all(lambda i : i.per_interact())
File "F:\Renpy\renpy\display\core.py", line 541, in visit_all
d.visit_all(callback, seen)
File "F:\Renpy\renpy\display\core.py", line 541, in visit_all
d.visit_all(callback, seen)
File "F:\Renpy\renpy\display\core.py", line 541, in visit_all
d.visit_all(callback, seen)
File "F:\Renpy\renpy\display\screen.py", line 430, in visit_all
callback(self)
File "F:\Renpy\renpy\display\core.py", line 3091, in <lambda>
root_widget.visit_all(lambda i : i.per_interact())
File "F:\Renpy\renpy\display\screen.py", line 440, in per_interact
self.update()
File "F:\Renpy\renpy\display\screen.py", line 625, in update
self.screen.function(**self.scope)
File "game/script.rpy", line 35, in execute
imagebutton idle item.img hover item.img_hover selected_idle item.img_hover action SetVariable("selected_item", item) xalign 0.5 yalign 0.5
File "game/script.rpy", line 35, in execute
imagebutton idle item.img hover item.img_hover selected_idle item.img_hover action SetVariable("selected_item", item) xalign 0.5 yalign 0.5
File "game/script.rpy", line 36, in execute
#imagebutton idle [itemz[sword][img]] action SetVariable("selected_item", item) xalign 0.5 yalign 0.5
File "game/script.rpy", line 37, in execute
show screen test_buttons
File "game/script.rpy", line 37, in keywords
show screen test_buttons
File "<screen language>", line 37, in <module>
NameError: name 'img' is not defined