After long and painful way I am almost finished with my UI. So I created items, item values, inventory that contains those items, skills connected to those items etc.
Now last thing I have to do is make equippable item and the way I imagined it to be is the most simple like this: (Make button that says "Equip Item" and after you click this button current item in inventory gets selected as primary weapon.) Let me start with the code so you can understand better:
class for items:
Code: Select all
init -1 python:
class Item(object):
def __init__(self, name, cost, wt, damagemin, damagemax, amount=0, desc="No Desc", picture = "No Picture", **kwargs):
self.name = name
self.cost = cost
self.wt = wt
self.damagemin = damagemin
self.damagemax = damagemax
self.amount = amount
self.desc = desc
self.picture = picture
Code: Select all
default gun = Item("Gun", 450, 1, 40, 80, 1, "Guns and code are fun combination!", "gun.png")
Code: Select all
screen item_desc(item):
add "gui/inventory_blank.png"
modal True
frame align (0.4, 0.5):
style_group "item_desc_grp"
at Position(xanchor = 0.0,xpos = 0.001, yanchor = 0.0, ypos = 0.80, xminimum = 10)
xminimum 1439
xmaximum 1439
yminimum 200
ymaximum 200
vbox:
text "[item.desc]"
$ renpy.block_rollback()
frame:
xpos 10
style_group "nice_looking"
xalign 0
yalign 0.015
textbutton "CLOSE" action Hide("item_desc")
frame align (0.5, 0.5):
image "[item.picture]"
frame align (0.4, 0.5):
style_group "item_desc_grp"
at Position(xanchor = 0.0,xpos = 0.001, yanchor = 0.0, ypos = 0.74, xminimum = 10)
vbox:
frame:
text "[item.name]"
frame align (0.2, 0.5):
textbutton "EQUIP THIS ITEM" action Jump("equip_gun") ####Here is the line where I got stuck...
Code: Select all
frame align (0.2, 0.5):
if "[item.name]" == [gun.name]:
textbutton "EQUIP THIS ITEM" action Jump("equip_gun")
elif "[item.name]" == [sword.name]:
textbutton "EQUIP THIS ITEM" action Jump("equip_sword")
##### ETC. for each item.
label equip_gun: # if gun is equipped
$ sword_is_now_equipped = False
$ gun_is_now_equipped = True
label equip_sword: # if sword is equipped
$ gun_is_now_equipped = False
$ sword_is_now_equipped = True