It runs perfectly by itself, but I can't seem to put an opening scene at the beginning to use it for a "Search the Haunted House" game. When I try to add an opening scene, or even just an image, I get something like this:
Code: Select all
I'm sorry, but an uncaught exception occurred.
While running game code:
File "game/script.rpy", line 33, in script
scene bg wallpaper with fade
File "game/screens.rpy", line 606, in python
for index,i in enumerate(hidden_items):
NameError: global name 'hidden_items' is not defined
-- Full Traceback ------------------------------------------------------------
Full traceback:
File "I:\!Kenetic Novels\RenPy\renpy-6.12.2\renpy\execution.py", line 261, in run
File "I:\!Kenetic Novels\RenPy\renpy-6.12.2\renpy\ast.py", line 1000, in execute
File "I:\!Kenetic Novels\RenPy\renpy-6.12.2\renpy\exports.py", line 870, in with_statement
File "I:\!Kenetic Novels\RenPy\renpy-6.12.2\renpy\display\core.py", line 1445, in do_with
File "I:\!Kenetic Novels\RenPy\renpy-6.12.2\renpy\display\core.py", line 1466, in with_none
File "I:\!Kenetic Novels\RenPy\renpy-6.12.2\renpy\display\core.py", line 1571, in compute_overlay
File "game/screens.rpy", line 606, in display_items_overlay
NameError: global name 'hidden_items' is not defined
Windows-post2008Server-6.1.7601-SP1
Ren'Py 6.12.2.1531
Antiques 0.0
This is the code I am using.
On the Screens page:
Code: Select all
#################################################
#Hidden Object Game
screen hidden_object:
tag hidden
imagemap:
auto hidden_files
for index, item in enumerate(hidden_items):
hotspot (item.x,item.y,item.w,item.h) action If(hidden_items[index].found==False, SetField(hidden_items[index],"found",True), None)
if is_all_found():
textbutton "All Objects Found!" xalign 0.5 yalign 0.5 action Return("Completed")
init -2 python:
class Item:
def __init__(self, name, x,y,w,h):
self.name = name
self.x = x
self.y = y
self.w = w
self.h = h
self.found = False
showitems = True
config.imagemap_cache = False
parlor_items = []
parlor_items.append(Item("landscape,", 852,241,128,189))
parlor_items.append(Item("phonograph,", 834,493,149,183))
parlor_items.append(Item("hat,", 782,407,78,73))
parlor_items.append(Item("cake,", 786,615,50,36))
parlor_items.append(Item("phone,", 721,492,105,85))
parlor_items.append(Item("tick-tock,", 656,379,122,91))
parlor_items.append(Item("fish,", 684,155,104,47))
parlor_items.append(Item("boxing,", 611,244,60,128))
parlor_items.append(Item("cane,", 589,366,29,148))
parlor_items.append(Item("horse,", 355,501,244,171))
parlor_items.append(Item("tea,", 295,486,75,43))
parlor_items.append(Item("bottle,", 371,287,42,95))
parlor_items.append(Item("car,", 220,164,122,60))
parlor_items.append(Item("perfumes,", 285,562,69,52))
parlor_items.append(Item("books,", 183,580,101,98))
parlor_items.append(Item("cheese,", 74,631,87,48))
parlor_items.append(Item("pillow,", 161,465,114,93))
parlor_items.append(Item("cat,", 73,466,114,90))
parlor_items.append(Item("vase,", 38,556,36,122))
parlor_items.append(Item("Lady and Gent,", 36,244,136,182))
def display_items_overlay():
if showitems:
ui.frame(id="obj_list")
ui.hbox(id="display_hbox",spacing=5,box_wrap = True)
for index,i in enumerate(hidden_items):
inventory_prefix = ""
inventory_suffix = ""
item_name = i.name
item_state = i.found
if item_state == True:
inventory_prefix = "{s}"
inventory_suffix = "{/s}"
item_text = inventory_prefix+item_name+inventory_suffix
item_index = "object_%d" % (index)
ui.text(item_text,id=item_index)
ui.close()
config.overlay_functions.append(display_items_overlay)
def is_all_found():
for i in hidden_items:
if i.found == False:
return False
return True
def resetItems(in_items):
for i in in_items:
i.found = False
Code: Select all
init:
image bg bedroom = "bedroom_empty.png"
image bg parlor = "parlor_empty.png"
image bg study = "study_empty.png"
image bg wallpaper = "bg_01.jpg"
image bg wood = "bg_02.jpg"
image Miss01 = "Miss01.png"
image splash = "000.png"
$renpy.music.register_channel("nature", "music", True)
label splash:
$ renpy.pause(0)
scene black
with Pause(0.5)
show splash with dissolve
with Pause(2.0)
scene black with dissolve
with Pause(1.0)
return
label start:
scene bg wallpaper with fade
show Miss01 at right with dissolve
"This is a little hidden object game. Ready?"
"Oh, one more thing! You're being timed. Enjoy!"
label game:
$ game = renpy.time.time()
$ resetItems(parlor_items)
$ hidden_files = "parlor_%s.png"
$ hidden_items = renpy.random.sample(parlor_items,8)
call screen hidden_object
scene bg parlor
$ elapsed = (renpy.time.time() - game)
"Result: %(_return)s in %(elapsed)d seconds!"
"All done."
label end:
scene bg wallpaper with fade
show Miss01 at right with dissolve
"I hope you enjoyed that. It's still in the experimental stage, so it's not very impressive at the moment. Even so, would you like to play again?"
menu:
"Play again?":
jump game2
"No thanks. Show me the credits.":
return