I have a feeling I'll be posting a lot in here because I'm fairly new to the whole coding thing, but I've been trying my best to make things work. I've been trying to solve this for several hours but had no luck whatsoever! All I'm trying to do is make a scene for when you go buy things. However, when I first did it on my own without what I added now, if the player had $0 they could still buy an object even if i put that the money had to be >= 10, for instance.
This would just make the money go down in the negatives. So I tried using the renpy cookbook and other things for help. And this happened. I'm not sure how to fix it. I apologize for the mess I'm going to put below since I was trying to figure out a way to make things work.
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 546, in script call
call Shop
File "game/Daily_Things.rpy", line 135, in script
if inventory.buy(roses):
File "game/Daily_Things.rpy", line 135, in <module>
if inventory.buy(roses):
NameError: name 'inventory' is not defined
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "game/script.rpy", line 546, in script call
call Shop
File "game/Daily_Things.rpy", line 135, in script
if inventory.buy(roses):
File "C:\Users\Gen\Desktop\Super cool game stuff\renpy-6.99.8-sdk\renpy\ast.py", line 1648, in execute
if renpy.python.py_eval(condition):
File "C:\Users\Gen\Desktop\Super cool game stuff\renpy-6.99.8-sdk\renpy\python.py", line 1606, in py_eval
return py_eval_bytecode(code, globals, locals)
File "C:\Users\Gen\Desktop\Super cool game stuff\renpy-6.99.8-sdk\renpy\python.py", line 1601, in py_eval_bytecode
return eval(bytecode, globals, locals)
File "game/Daily_Things.rpy", line 135, in <module>
if inventory.buy(roses):
NameError: name 'inventory' is not defined
Windows-8-6.2.9200
Ren'Py 6.99.10.1227
Lady Killers 0.0
Code: Select all
## Insert Shop Details here
python:
##FLOWERS
roses = item("Bouquet of Roses", 10)
tulips = item("Bouquet of Tulips", 10)
daisies = item("Bouquet of Daisies", 10)
label Shop:
scene store
play music storesong
$ showmoney = True
shop " Hi, what would you like to buy today?"
label buy:
$ inventory = Inventory()
scene store
menu:
"Flowers":
menu:
"Bouquet of Roses":
show roses at center
shop " That'll cost $10."
menu:
" I'll buy it.":
if inventory.buy(roses):
" Thanks for your purchase!"
else:
"Not enough money..."
" Eh, nevermind.":
jump buy_more
"Bouquet of Tulips":
show tulips at center
shop " That'll cost $10."
menu:
" I'll buy it.":
if inventory.buy(tulips):
" Thanks for your purchase!"
else:
"Not enough money..."
" Eh, nevermind.":
jump buy_more
"Bouquet of Daisies":
show daisies at center
shop " That'll cost $10."
menu:
" I'll buy it.":
if inventory.buy(daisies):
" Thanks for your purchase!"
else:
"Not enough money..."
" Eh, nevermind.":
jump buy_more
label buy_more:
scene store
shop " Anything else?"
menu:
" No":
shop " Have a nice day and come back real soon!"
jump home
"Yes.":
jump buy
Code: Select all
#############################
init:
$ TIME = 0
$ items = []
$ Day = 1
$ money = 10
######################STUFF FOR SHOP!!
init python:
class item:
def __init__(self, name, cost):
self.name = name
self.cost = cost
class Inventory:
def __init__(self, money=10):
self.money = money
self.items = []
##ABOVE IS INITIAL STUFF??
def buy(self, item):
if self.money >= item.cost:
self.money -= item.cost
self.items.append(item)
return True
else:
return False
##ABOVE IS FOR BUYING STUFF
def earn(self, amount):
self.money += amount
##ABOVE MEANS U EARN MONEY
Thank you so much in advance!!