i've got this:
Code: Select all
# You can place the script of your game in this file.
python:
inventory = Inventory()
spaghetti = Item("Spaghetti", 3)
olives = Item("Olives", 4)
chocolate = Item("Chocolate", 11)
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 = []
def buy(self, item):
if self.money >= item.cost:
self.money -= item.cost
self.items.append(item)
return True
else:
return False
def earn(self, amount):
self.money += amount
def has_item(self, item):
if item in self.items:
return True
else:
return False
init:
# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"
# Declare characters used by this game.
$ e = Character('Eileen', color="#c8ffc8")
# The game starts here.
label start:
"Oh, look! I found ten coins!"
$ inventory.earn(10)
$ current_money = inventory.money
"Now I have %(current_money)d coins."
"My stomach growls loudly."
if inventory.buy(chocolate):
"Mmm, chocolate. I'll save that for later... "
else:
"Not enough money... "
"Suddenly, I feel hungry."
jump preshop
jump shop2
if inventory.has_item(chocolate):
"Good thing I bought that chocolate earlier."
else:
"If only I had some chocolate..."
label preshop:
$ spaghetticost = spaghetti.cost
$ olivescost = olives.cost
$ chocolatecost = chocolate.cost
label shop2:
menu shop:
"I go into the store."
"Buy spaghetti for %(spaghetticost)d coins.":
if inventory.buy(spaghetti):
"Hey, those are uncooked. I can't eat those yet!"
jump game_continues
"Buy olives for %(olivescost)d coins.":
if inventory.buy(olives):
"I hate olives."
"And they cost more than the spaghetti."
"But at least I don't have to cook them... "
jump game_continues
"Buy chocolate for %(chocolatecost)d coins.":
if inventory.buy(chocolate):
"Mmmm, dark semi-sweet chocolate! My favorite!"
jump game_continues
"Buy nothing.":
jump game_continues
label fallthrough:
"Not enough money..."
jump shop2
label game_continues:
"And so I left the store."
Code: Select all
I'm sorry, but an exception occured while executing your Ren'Py
script.
TypeError: unbound method earn() must be called with inventory instance as first argument (got int instance instead)
While running game code:
- script at line 54 of L:\Visual Novels\software\renpy-6.10.0\test/game/script.rpy
- python at line 54 of L:\Visual Novels\software\renpy-6.10.0\test/game/script.rpy.
-- Full Traceback ------------------------------------------------------------
File "L:\Anime\Visual Novels\software\renpy-6.10.0\renpy\bootstrap.py", line 260, in bootstrap
File "L:\Anime\Visual Novels\software\renpy-6.10.0\renpy\main.py", line 308, in main
File "L:\Anime\Visual Novels\software\renpy-6.10.0\renpy\main.py", line 92, in run
File "L:\Anime\Visual Novels\software\renpy-6.10.0\renpy\execution.py", line 230, in run
File "renpy-6.10.0/renpy/ast.py", line 557, in execute
File "L:\Anime\Visual Novels\software\renpy-6.10.0\renpy\python.py", line 927, in py_exec_bytecode
File "L:\Visual Novels\software\renpy-6.10.0\test/game/script.rpy", line 54, in <module>
TypeError: unbound method earn() must be called with inventory instance as first argument (got int instance instead)
While running game code:
- script at line 54 of L:\Visual Novels\software\renpy-6.10.0\test/game/script.rpy
- python at line 54 of L:\Visual Novels\software\renpy-6.10.0\test/game/script.rpy.
Ren'Py Version: Ren'Py 6.10.0e