This is the text I can't get, it should come if self.money is lower than item.cost but it never shows.
Code: Select all
def buy(self, item):
if (self.money >= item.cost):
self.items.append(item)
self.money -= item.cost
else:
"You can't afford [item.name] it costs [item.cost]$. You have [self.money]$"
Code: Select all
init -2 python:
import renpy.store as store
import renpy.exports as renpy
inventory_page = 0
item = None
class Item(store.object):
def __init__(self, name, cost=0):
self.name = name
self.cost = cost
def use(self):
inventory.drop(self)
class Inventory(store.object):
def __init__(self, money=0):
self.money = money
self.items = []
def add(self, item):
self.items.append(item)
def drop(self, item):
self.items.remove(item)
def buy(self, item):
if (self.money >= item.cost):
self.items.append(item)
self.money -= item.cost
else:
"You can't afford [item.name] it costs [item.cost]$. You have [self.money]$"
def add_money(self, amount):
self.money += amount
Code: Select all
chocolate = Item("Chocolate", 5)
wine = Item("Wine", 30)
Code: Select all
$ inventory.buy(chocolate)
$ inventory.buy(wine)