I used the second example of this tutorial: https://www.renpy.org/wiki/renpy/doc/co ... ney_System and as long as I only pasted, copied and modified the code, everything worked. But, when I tried to move some piece of the tutorial's modified code in order to fit it in my code, the game, every time, and only when I try to use some button that use the inventory, send this error:
[issue]NameError: name 'inventory' is not defined[/issue]
I don't know what to do. I tried something, like moving the tutorial's code in other points of my code, but nothing changed.
Thank to everyone.
Here's what matter of my code.
Code: Select all
init:
image white = Solid((255, 255, 255, 255))
# MC Variables
$ strength = 1
$ intelligence = 1
$ charisma = 1
$ level = 1
# Time
$ day = 1
$ daytime = 0
# Utility
$ random = 0
transform transformTop:
xpos 0
ypos -2000
easein 10 xpos 0 ypos 0
python:
class Item:
def __init__(self, name, cost):
self.name = name
self.cost = cost
class Inventory:
def __init__(self, money=0):
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 hasitem(self, item):
if item in self.items:
return True
else:
return False
def additem(self, item):
self.items.append(item)
################################################################################
label map_menu:
scene map
menu:
"Go find some loot.":
jump loot
################################################################################
# loot system
label loot:
scene map
menu:
"Where I go to gather some loot?"
"Zone 1":
$ random = renpy.random.randint(1,20)
jump zone1_loot
"Zone 2":
$ random = renpy.random.randint(1,20)
jump zone2_loot
"Zone 3":
$ random = renpy.random.randint(1,31)
jump zone3_loot
"Zone 4":
$ random = renpy.random.randint(1,20)
jump zone4_loot
"Zone 5":
$ random = renpy.random.randint(1,20)
jump zone5_loot
"Go back":
jump map_menu
label zone1_loot:
scene zone1_loot
if level < 1:
"Your level is too low for this floor."
jump loot
else:
if random >= 15:
"You found a Dire Wolf!"
$ inventory.additem(wolffur)
"1 wolf's fur added to your inventory."
if daytime >= 3:
$ daytime = 0
else:
$ daytime = daytime + 1
$ random = 0
jump amp_menu
if random >= 8:
"You found a Thicket Spider!"
$ inventory.additem(spiderleg)
"1 spider's leg added to your inventory."
if daytime >= 3:
$ daytime = 0
else:
$ daytime = daytime + 1
$ random = 0
jump map_menu
if random >= 0:
"You found a Frenzy Boar!"
$ inventory.additem(boarfur)
"1 boar's fur added to you inventory."
if daytime >= 3:
$ daytime = 0
else:
$ daytime = daytime + 1
$ random = 0
jump map_menu
################################################################################
# The game starts here.
label start:
#settingupitems
$ money = inventory.money
python:
inventory = Inventory()
wolffur = Item("Wolf's Fur", 3)
spiderleg = Item("Spider's Leg", 2)
boarfur = Item("Boar's Fur", 1)
$ wolffurcost = wolffur.cost
$ spiderlegcost = spiderleg.cost
$ boarfurcost = boarfur.cost
“Here’s the story”
jump map_menu