Hidden Object Code

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
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.
Message
Author
User avatar
Aleema
Lemma-Class Veteran
Posts: 2677
Joined: Fri May 23, 2008 2:11 pm
Organization: happyB
Tumblr: happybackwards
Contact:

Re: Hidden Object Code

#16 Post by Aleema » Wed Sep 07, 2011 7:29 am

The hint error might be coming from this code:

Code: Select all

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
            self.hint = hint
(Sorry, can't help fix, not familiar with whole code.)

User avatar
SusanTheCat
Miko-Class Veteran
Posts: 952
Joined: Mon Dec 13, 2010 9:30 am
Location: New Brunswick, Canada
Contact:

Re: Hidden Object Code

#17 Post by SusanTheCat » Wed Sep 07, 2011 9:02 am

Aleema -- you are right

Code: Select all

def __init__(self, name, x,y,w,h):
Should be

Code: Select all

 def __init__(self, name, x,y,w,h,hint=False):
Susan
" It's not at all important to get it right the first time. It's vitally important to get it right the last time. "
— Andrew Hunt and David Thomas

User avatar
Soraminako
Veteran
Posts: 277
Joined: Sun Sep 04, 2011 1:36 am
Projects: A thingie without a title. With messy code.
Contact:

Re: Hidden Object Code

#18 Post by Soraminako » Wed Sep 07, 2011 4:12 pm

That code is very useful!! :D

Just a question though, because I'm a noob.

I see it has a timer. If I want to make the mini-game not have a time limit, how do I do it?

Thank you in advance if anyone can let me know!!
(I drew my avatar especially to express the scary feeling I get from the code as I type it... XD)

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1779
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: Hidden Object Code

#19 Post by OokamiKasumi » Wed Sep 07, 2011 4:46 pm

SusanTheCat wrote:Aleema -- you are right

Code: Select all

def __init__(self, name, x,y,w,h):
Should be

Code: Select all

 def __init__(self, name, x,y,w,h,hint=False):
Susan
More accurately:

Code: Select all

class Item:
        def __init__(self, name, x,y,w,h,hint=False):
            self.name = name
            self.x = x
            self.y = y
            self.w = w
            self.h = h
            self.found = False
            self.hint = hint
Thank you, that works perfectly!
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

User avatar
SusanTheCat
Miko-Class Veteran
Posts: 952
Joined: Mon Dec 13, 2010 9:30 am
Location: New Brunswick, Canada
Contact:

Re: Hidden Object Code

#20 Post by SusanTheCat » Mon Sep 26, 2011 6:24 pm

Code to register extra clicks!

Add to top (right above class getHint(Action) works)

Code: Select all

    class registerClick(Action):
        def __call__(self):
            global num_clicks
            num_clicks += 1
            renpy.restart_interaction()
Add giant button to imagemap:

Code: Select all

    imagemap:
        auto hidden_files
        cache False
        textbutton "Hint" xalign 1.0 yalign 0.0 action getHint()
        imagebutton auto "empty_%s.png" action registerClick()
        for index, item in enumerate(hidden_items):
You need to create a blank transparent png files the same size as the background. Their names should be: empty_ground.png, empty_hover.png, empty_idle.png, empty_insensitive.png Example attached.

Add new variable:

Code: Select all

    $ num_hints = 3
    $ num_clicks = 0
Afterwards you can report the number of extra clicks:

Code: Select all

    "Result: %(_return)s in %(elapsed)d with %(num_clicks)d extra clicks!"
Susan
Attachments
empty_ground.png
empty_ground.png (2.82 KiB) Viewed 1094 times
" It's not at all important to get it right the first time. It's vitally important to get it right the last time. "
— Andrew Hunt and David Thomas

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1779
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: Hidden Object Code

#21 Post by OokamiKasumi » Tue Sep 27, 2011 5:34 am

SusanTheCat wrote:Code to register extra clicks! -- Susan
You are a GODDESS!

Now, how do I set this to toss the player out of that game to a neutral label? Would that be with this?

Code: Select all

    class registerClick(Action):
        def __call__(self):
            global num_clicks
            num_clicks += 1
            renpy.restart_interaction()
What I'd like to do is after a total of 3 wrong clicks, jump them to something like:

Code: Select all

label study_oops
    scene stairs01 with fade
    show Miss01 with dissolve
    "Whoops! You've made one too many bad choices. Shall we try it again?"
    hide Miss01 with dissolve
    jump study_game
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

User avatar
KimiYoriBaka
Miko-Class Veteran
Posts: 636
Joined: Thu May 14, 2009 8:15 pm
Projects: Castle of Arhannia
Contact:

Re: Hidden Object Code

#22 Post by KimiYoriBaka » Tue Sep 27, 2011 7:51 pm

just add this after adding to num_clicks

Code: Select all

if num_clicks>=3:
    num_clicks = 0
    renpy.jump('study_oops')
then make a variable that keeps track of which room the player is in, so your generic label can know which room to send the player to.

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1779
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: Hidden Object Code

#23 Post by OokamiKasumi » Tue Sep 27, 2011 9:20 pm

KimiYoriBaka wrote:just add this after adding to num_clicks

Code: Select all

if num_clicks>=3:
    num_clicks = 0
    renpy.jump('study_oops')
then make a variable that keeps track of which room the player is in, so your generic label can know which room to send the player to.
Kimi, you're brilliant! Thank you.
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

User avatar
SusanTheCat
Miko-Class Veteran
Posts: 952
Joined: Mon Dec 13, 2010 9:30 am
Location: New Brunswick, Canada
Contact:

Re: Hidden Object Code

#24 Post by SusanTheCat » Tue Sep 27, 2011 9:32 pm

Thanks Kimi!
I knew that function existed, but I couldn't remember what it was. :)

Susan
" It's not at all important to get it right the first time. It's vitally important to get it right the last time. "
— Andrew Hunt and David Thomas

User avatar
SusanTheCat
Miko-Class Veteran
Posts: 952
Joined: Mon Dec 13, 2010 9:30 am
Location: New Brunswick, Canada
Contact:

Re: Hidden Object Code

#25 Post by SusanTheCat » Mon Jan 30, 2012 10:07 pm

Would people like a step by step tutorial on how to use the code?

Susan
" It's not at all important to get it right the first time. It's vitally important to get it right the last time. "
— Andrew Hunt and David Thomas

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1779
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: Hidden Object Code

#26 Post by OokamiKasumi » Tue Jan 31, 2012 4:24 am

SusanTheCat wrote:Would people like a step by step tutorial on how to use the code?
-- Susan
YES PLEASE! Could you include your 'hint' code and the click-penalty code?
-- I cannot get those two to work simultaneously no matter what I do.
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

User avatar
AERenoir
Veteran
Posts: 318
Joined: Fri May 27, 2011 8:23 pm
Contact:

Re: Hidden Object Code

#27 Post by AERenoir » Tue Jan 31, 2012 11:44 pm

Oh definitely yes PLEASE. I'm a bit weak with codes, and I learn better with step by step tutorials.

Say, if I want to declare the hidden object script elsewhere and not just dunk it into the scene itself what do I do? Where do I put the script so I can call it?

User avatar
OokamiKasumi
Eileen-Class Veteran
Posts: 1779
Joined: Thu Oct 14, 2010 3:53 am
Completed: 14 games released -- and Counting.
Organization: DarkErotica Games
Deviantart: OokamiKasumi
Location: NC, USA
Contact:

Re: Hidden Object Code

#28 Post by OokamiKasumi » Wed Feb 01, 2012 12:00 am

AERenoir wrote:...Say, if I want to declare the hidden object script elsewhere and not just dunk it into the scene itself what do I do? Where do I put the script so I can call it?
I put my hidden object code on the Screens page as a Screen:

Code: Select all

#################################################
#Hidden Object Game

screen hidden_object:
    tag hidden
    
    imagemap:
        auto hidden_files
        hotspot (896,676,126,90) action getHint()   
        for index, item in enumerate(hidden_items):
            hotspot (item.x,item.y,item.w,item.h) action If(hidden_items[index].found==False, SetItem(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 getHint(Action):
        def __call__(self):
            global num_hints
            num_hints -= 1
            for index,i in enumerate(hidden_items):
                if i.found == False and i.hint == False:
                    i.hint = True
                    break
            renpy.restart_interaction()
            
        def get_sensitive(self):
            global num_hints
            return num_hints > 0
    
    class SetItem(Action):
        def __init__(self, object, field, value):
            self.object = object
            self.field = field
            self.value = value
        
        def __call__(self):
            setattr(self.object, self.field, self.value)
            renpy.restart_interaction()

        def get_selected(self):
            return getattr(self.object, "hint") == True
    
    class Item:
        def __init__(self, name, x,y,w,h,hint=False):
            self.name = name
            self.x = x
            self.y = y
            self.w = w
            self.h = h
            self.found = False
            self.hint = hint
            
    showitems = False
    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("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
Then, on the Script page, I Called that screen:

Code: Select all

label parlor_game:   
    hide Miss01
    scene black
    
    $ showitems = False
    
    play music "02 - the dragonfly.mp3" fadeout 1.0 
    
    $ game = renpy.time.time()
    $ resetItems(parlor_items)
    $ hidden_files = "parlor_%s.png"
    $ hidden_items = renpy.random.sample(parlor_items,10)
    $ num_hints = 3
    
    $ showitems = True
    call screen hidden_object
    
    scene bg parlor 
    $ elapsed = (renpy.time.time() - game)
    "Result: %(_return)s in %(elapsed)d seconds!"          
    $ showitems = False
    
    show Miss01 at right with dissolve 
    "Oh dear, what I'm looking for wasn't in the parlor."
    "I suppose you're wondering why the place has so many old fashioned things in it. Well, it's because I've been here for a {i}very{/i} long time."
    "Shall we look in another room?" 
    
    jump room_choice
Ookami Kasumi ~ Purveyor of fine Smut.
Most recent Games Completed: For ALL my completed games visit: DarkErotica Games

"No amount of great animation will save a bad story." -- John Lasseter of Pixar

Post Reply

Who is online

Users browsing this forum: No registered users