I try to build a buying system. I have kinda manage to build a simple one and have a basic shop set up.
The problem is when i try to use textbutton as the "buy" function.
I can't click it.
but clicking on the pictures of the items available, i can see my gold coins reduced. This is not what i intended. i don't want to purchase anything when i click on stuff to check the price.
The gold coin reduced in a weird way.
When i click on the a item pic, nothing happened
when i click on the another item pic, the gold amount reduced as the cost of the previous item x2
basically each image become a "buy" button x2 of the previously clicked image
(I never wanted to do that!!!)
What did i do wrong?
Code: Select all
style slot:
#these two styles are styles for the inventory/seller window
background Frame("square")
xalign 0.5
minimum(150,300)
maximum(150,300)
style horizontal_slot:
xalign 0.5
yalign 0.6
background Frame("horizontal")
minimum(300,150)
maximum(300,150)
screen buying_dress:
#this is the vpgrid to show the images items to be purchased
vpgrid:
cols 3
draggable True
mousewheel True
xmaximum 500
xminimum 500
ymaximum 450
yminimum 450
yalign 0.2
xalign 0.5
spacing 5
for Item in ClothingShopItenery:
imagebutton:
style "slot"
idle Item.img
action SetVariable("selected_item", Item)
vbox: #this box to is show the info of the selected item
xalign 0.5
yalign 0.89
frame:
style "horizontal_slot"
vbox:
if selected_item != None:
label "Cost: [selected_item.cost]"
label "Name: [selected_item.name]"
textbutton "BUY":
xalign 0.7
yalign 0.95
sensitive
selected
if selected_item != None:
action inventory.buy(selected_item)
textbutton "Return":
action Return()
xalign 0.5
yalign 0.95
init python:
class Inventory:
def __init__(self):
self.items = []
def buy(self, item):
global gold
global justbought
if gold >= item.cost:
gold -= item.cost
self.items.append(item)
justbought = item.name
#global selected_item
#selected_item = None
class Item:
def __init__(self, name, cost, img):
self.name = name
self.cost = cost
self.img = img
default ClothingShopItenery = []
default shirt1= Item("Shirt 1", 5, "shirt a buying.png")
default shirt2= Item("Shirt 2", 10, "shirt a buying.png")
default shirt3= Item("Shirt 3", 15, "shirt b buying.png")
default shirt4= Item("Shirt 4", 20, "shirt b buying.png")
screen Goldcoins:
text "Goldcoins [gold]" xpos 0.065 ypos 0.125
label start:
show screen Goldcoins
scene bg white
python:
inventory = Inventory()
ClothingShopItenery.append(shirt1)
ClothingShopItenery.append(shirt2)
ClothingShopItenery.append(shirt3)
ClothingShopItenery.append(shirt4)
selected_item = None
gold = 300
"go to clothing shop"
call screen buying_dress