How do you use the On-Screen Inventory code?
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
- Kokoro Hane
- Eileen-Class Veteran
- Posts: 1219
- Joined: Thu Oct 27, 2011 6:51 pm
- Completed: 30 Kilowatt Hours Left, The Only One Girl { First Quarter }, An Encounter ~In The Rain~, A Piece of Sweetness, Since When Did I Have a Combat Butler?!, Piece by Piece, +many more
- Projects: Fateful Encounter, Operation: Magic Hero
- Organization: Tofu Sheets Visual
- Deviantart: kokoro-hane
- itch: tofu-sheets-visual
- Contact:
How do you use the On-Screen Inventory code?
http://www.renpy.org/wiki/renpy/doc/coo ... _Inventory
I am having trouble with this code (the first one, inventory). I have no idea how it works or how to implement it. It would be a REALLY USEFUL code to me, if I could get it to work. Thanks in advanced!
I am having trouble with this code (the first one, inventory). I have no idea how it works or how to implement it. It would be a REALLY USEFUL code to me, if I could get it to work. Thanks in advanced!
PROJECTS:
Operation: Magic Hero [WiP]
Piece By Piece [COMPLETE][Spooktober VN '20]
RE/COUNT RE:VERSE [COMPLETE][RPG]
Since When Did I Have a Combat Butler?! [COMPLETE][NaNoRenO2020+]
Crystal Captor: Memory Chronicle Finale [COMPLETE][RPG][#1 in So Bad It's Good jam '17]
But dear God, You're the only North Star I would follow this far
Owl City "Galaxies"
Operation: Magic Hero [WiP]
Piece By Piece [COMPLETE][Spooktober VN '20]
RE/COUNT RE:VERSE [COMPLETE][RPG]
Since When Did I Have a Combat Butler?! [COMPLETE][NaNoRenO2020+]
Crystal Captor: Memory Chronicle Finale [COMPLETE][RPG][#1 in So Bad It's Good jam '17]
But dear God, You're the only North Star I would follow this far
Owl City "Galaxies"
Re: How do you use the On-Screen Inventory code?
Ohh, inventory codes, how fun! There's a few things that got left out of the explanation though; at the moment it looks like it would just cause a few errors instead of showing anything?
You're probably going to have to make a few changes depending on what you want it to look like or what you want it to do. The two lines with !!! in them especially have to be figured out (though you probably want the bottom one, which is much simpler).
Code: Select all
init python:
showitems = True # The inventory screen will pop up whenever this is True and hides
# when it's False.
items = [] # This wasn't in the sample code, but it's where you keep track of items.
# Eventually you can fill it with items, so it would be more like ["Eggs", "Cheese"]
def display_items_overlay():
if showitems:
inventory_show = "Inventory: "
for i in range(0, len(items)): # This will go through your list of items
!!! item_name = items[i].title() # This is a problem line (read: ERROR); this requires that items be a class (more complex and also undefined at the moment)
!!! item_name = items[i] # Replace the line above if you want it to be a simple inventory, or delete this
if i > 0: # If the item is the first item in your inventory, don't add a comma before it
inventory_show += ", "
inventory_show += item_name # This line now reads "Inventory: Item1, Item2, ..." and so on
ui.frame()
ui.text(inventory_show) # The ui functions are what display everything to the screen.
config.overlay_functions.append(display_items_overlay) # And this makes the function display depending on showitems
Last edited by kankan on Wed Sep 19, 2012 7:36 pm, edited 1 time in total.
- Kokoro Hane
- Eileen-Class Veteran
- Posts: 1219
- Joined: Thu Oct 27, 2011 6:51 pm
- Completed: 30 Kilowatt Hours Left, The Only One Girl { First Quarter }, An Encounter ~In The Rain~, A Piece of Sweetness, Since When Did I Have a Combat Butler?!, Piece by Piece, +many more
- Projects: Fateful Encounter, Operation: Magic Hero
- Organization: Tofu Sheets Visual
- Deviantart: kokoro-hane
- itch: tofu-sheets-visual
- Contact:
Re: How do you use the On-Screen Inventory code?
Ooh, thank you very much! These all go in the Init section of the script, correct?
PROJECTS:
Operation: Magic Hero [WiP]
Piece By Piece [COMPLETE][Spooktober VN '20]
RE/COUNT RE:VERSE [COMPLETE][RPG]
Since When Did I Have a Combat Butler?! [COMPLETE][NaNoRenO2020+]
Crystal Captor: Memory Chronicle Finale [COMPLETE][RPG][#1 in So Bad It's Good jam '17]
But dear God, You're the only North Star I would follow this far
Owl City "Galaxies"
Operation: Magic Hero [WiP]
Piece By Piece [COMPLETE][Spooktober VN '20]
RE/COUNT RE:VERSE [COMPLETE][RPG]
Since When Did I Have a Combat Butler?! [COMPLETE][NaNoRenO2020+]
Crystal Captor: Memory Chronicle Finale [COMPLETE][RPG][#1 in So Bad It's Good jam '17]
But dear God, You're the only North Star I would follow this far
Owl City "Galaxies"
Re: How do you use the On-Screen Inventory code?
Code: Select all
if i < 0:Code: Select all
if i > 0:Re: How do you use the On-Screen Inventory code?
Yikes, I messed it up on accident. You're right, I'll fix it. Thanks!rasburn wrote:I instinctively feel this should be replaced byCode: Select all
if i < 0:but haven't tried the code. Am I wrong?Code: Select all
if i > 0:
And yep, this goes into the init section!
- asatiir
- Regular
- Posts: 86
- Joined: Tue Oct 01, 2013 6:04 pm
- Completed: Within the Walls (Twine)
- Projects: Roses Will Rise
- Organization: Asatiir's Tales
- Skype: asatiir
- itch: asatiir
- Location: Dubai, UAE
- Contact:
Re: How do you use the On-Screen Inventory code?
I spent the past week trying to figure out how this inventory system works and I'm really lost and my script is error-ridden, can someone please post an example how it really works?
Re: How do you use the On-Screen Inventory code?
It is better to post error message you've got and part of your code to let people find the problem.
Here it is an example of code
http://docs.python.org/2/tutorial/datastructures.html
Also, this might be useful for you - http://lemmasoft.renai.us/forums/viewto ... 51&t=23071
Here it is an example of code
Code: Select all
# Declare characters used by this game.
define e = Character('Eileen', color="#c8ffc8")
init python:
showitems = True
def display_items_overlay():
if showitems:
inventory_show = "Inventory: "
for i in range(0, len(items)):
item_name = items[i].title() # all the things are taken from list named "items"
if i > 0:
inventory_show += ", "
inventory_show += item_name
ui.frame()
ui.text(inventory_show)
config.overlay_functions.append(display_items_overlay)
# The game starts here.
label start:
$ showitems = False # will hide inventory
$ items = [] # an empty inventory list named "items"
e "You got nothing yet..."
$ showitems = True # will show inventory
e "See it?"
$ items.append("a new Ren\'Py game") # add an item to inventory list
e "You've created a new Ren'Py game."
e "Once you add a story, pictures, and music, you can release it to the world!"
$ items.append("an orange")
"You've found an orange..."
$ items.remove("an orange") # remove an item from inventory list
"... and ate it immediately."
"Om-nom-nom."
returnAlso, this might be useful for you - http://lemmasoft.renai.us/forums/viewto ... 51&t=23071
- asatiir
- Regular
- Posts: 86
- Joined: Tue Oct 01, 2013 6:04 pm
- Completed: Within the Walls (Twine)
- Projects: Roses Will Rise
- Organization: Asatiir's Tales
- Skype: asatiir
- itch: asatiir
- Location: Dubai, UAE
- Contact:
Re: How do you use the On-Screen Inventory code?
I was following that yesterday and couldn't figure it out, going back to what you posted, I got this error:
I'm sorry, but an uncaught exception occurred.
While running game code:
File "renpy/common/00start.rpy", line 122, in script call
File "game/script.rpy", line 34, in script
File "game/script.rpy", line 34, in python
File "game/script.rpy", line 10, in python
NameError: global name 'items' is not defined
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "C:\renpy-6.15.7-sdk\renpy\execution.py", line 288, in run
node.execute()
File "C:\renpy-6.15.7-sdk\renpy\ast.py", line 718, in execute
renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
File "C:\renpy-6.15.7-sdk\renpy\python.py", line 1297, in py_exec_bytecode
exec bytecode in globals, locals
File "game/script.rpy", line 34, in <module>
$ renpy.pause(0)
File "C:\renpy-6.15.7-sdk\renpy\exports.py", line 848, in pause
rv = renpy.ui.interact(mouse='pause', type='pause', roll_forward=roll_forward)
File "C:\renpy-6.15.7-sdk\renpy\ui.py", line 237, in interact
rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
File "C:\renpy-6.15.7-sdk\renpy\display\core.py", line 1853, in interact
repeat, rv = self.interact_core(preloads=preloads, **kwargs)
File "C:\renpy-6.15.7-sdk\renpy\display\core.py", line 1979, in interact_core
self.compute_overlay()
File "C:\renpy-6.15.7-sdk\renpy\display\core.py", line 1650, in compute_overlay
i()
File "game/script.rpy", line 10, in display_items_overlay
for i in range(0, len(items)):
NameError: global name 'items' is not defined
Windows-7-6.1.7601-SP1
Ren'Py 6.15.7.374
A Ren'Py Game 0.1alpha
Re: How do you use the On-Screen Inventory code?
Overlay functions are always shown onscreen, you've setthat means that the function will show inventory from the very beginning of the game, so at first you need to declare a list named "items" otherwise you'll get an error about "name "items" is not defined".
Check if you haveright at the beginning of start label (before anything else).
Code: Select all
init python:
showitems = TrueCheck if you have
Code: Select all
$ items = []- asatiir
- Regular
- Posts: 86
- Joined: Tue Oct 01, 2013 6:04 pm
- Completed: Within the Walls (Twine)
- Projects: Roses Will Rise
- Organization: Asatiir's Tales
- Skype: asatiir
- itch: asatiir
- Location: Dubai, UAE
- Contact:
Re: How do you use the On-Screen Inventory code?
I understood those parts, but I can't get past the previous error screen.
Re: How do you use the On-Screen Inventory code?
I'm not quite understand - do you still get the error message? If so - show the actual code you have (init block and start label) to let me or somebody else find an error.
- asatiir
- Regular
- Posts: 86
- Joined: Tue Oct 01, 2013 6:04 pm
- Completed: Within the Walls (Twine)
- Projects: Roses Will Rise
- Organization: Asatiir's Tales
- Skype: asatiir
- itch: asatiir
- Location: Dubai, UAE
- Contact:
Re: How do you use the On-Screen Inventory code?
Sure thing, I do appreciate your patience with this.
Code: Select all
# You can place the script of your game in this file.
# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"
image bg dream1 = "dream1.png"
# Declare characters used by this game.
define a = Character('Voice', color="#c8ffc8")
init python:
showitems = True
def display_items_overlay():
if showitems:
inventory_show = "Inventory: "
for i in range(0, len(items)):
item_name = items[i].title() # all the things are taken from list named "items"
if i > 0:
inventory_show += ", "
inventory_show += item_name
ui.frame()
ui.text(inventory_show)
config.overlay_functions.append(display_items_overlay)
##
$ items.append("stick") #when you want to add items
$ items.remove("stick")#when you want to remove items
$ showitems = False #when you don't want to show the inventory onscreen (cutscenes and the like)
$ showitems = True #when you want to reshow the inventory after the cutscene is over
label splashscreen:
$ renpy.music.play("Zombie Hoodoo.mp3")
$ renpy.pause(0)
scene black
show text "Within the Walls, The Wall and Within the Walls: Extended are works of fiction. None of the events represented in this interactive fiction portray or reflect in any way the beliefs of the author or anyone involved in the making of this game."
with dissolve
with Pause(10.0)
hide text
with dissolve
$ renpy.pause(0)
scene black
show text "Headphones are recommended."
with dissolve
with Pause(2.0)
hide text
with dissolve
$ renpy.pause(0)
scene black
show text "Zombie Camel Games Presents..."
with dissolve
with Pause(2.0)
hide text
with dissolve
return
init:
# Use it in subtitle mode.
$ esubtitle = Character(None,
what_size=50,
what_outlines=[(3, "#000000", 2, 2), (3, "#000000", 0, 0)],
what_layout="subtitle",
what_xalign=0.5,
what_text_align=0.5,
window_background=None,
window_yminimum=0,
window_xfill=False,
window_xalign=0.5)
# The game starts here.
label start:
$ showitems = False # will hide inventory
$ items = [] # an empty inventory list named "items"
scene black
$ renpy.music.stop(channel="music", fadeout=3)
esubtitle "Choose your story."
menu:
"Within the Walls":
jump withinthewalls1
"Within the Walls: Extended":
jump withinthewalls2
"The Wall (the original short story)":
jump thewallRe: How do you use the On-Screen Inventory code?
Well, the thing happens 'cause your game starts not at start label, but at splashscreen label - Ren'Py is trying to show inventory at that point, but "items" list will be defined only at start label.
To fix this just setso your inventory function won't be searching for "items" to show at the very beginning of the game and you'll be able to define it at start label and only then change "showitems" value to True.
To fix this just set
Code: Select all
init python:
showitems = False- asatiir
- Regular
- Posts: 86
- Joined: Tue Oct 01, 2013 6:04 pm
- Completed: Within the Walls (Twine)
- Projects: Roses Will Rise
- Organization: Asatiir's Tales
- Skype: asatiir
- itch: asatiir
- Location: Dubai, UAE
- Contact:
Re: How do you use the On-Screen Inventory code?
That makes so much more sense, so I have to leave the value as false until I open it back on start?
Who is online
Users browsing this forum: Bing [Bot], Google [Bot]

