Page 2 of 2

Re: Hidden Object Code

Posted: Wed Sep 07, 2011 7:29 am
by Aleema
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.)

Re: Hidden Object Code

Posted: Wed Sep 07, 2011 9:02 am
by SusanTheCat
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

Re: Hidden Object Code

Posted: Wed Sep 07, 2011 4:12 pm
by Soraminako
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!!

Re: Hidden Object Code

Posted: Wed Sep 07, 2011 4:46 pm
by OokamiKasumi
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!

Re: Hidden Object Code

Posted: Mon Sep 26, 2011 6:24 pm
by SusanTheCat
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

Re: Hidden Object Code

Posted: Tue Sep 27, 2011 5:34 am
by OokamiKasumi
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

Re: Hidden Object Code

Posted: Tue Sep 27, 2011 7:51 pm
by KimiYoriBaka
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.

Re: Hidden Object Code

Posted: Tue Sep 27, 2011 9:20 pm
by OokamiKasumi
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.

Re: Hidden Object Code

Posted: Tue Sep 27, 2011 9:32 pm
by SusanTheCat
Thanks Kimi!
I knew that function existed, but I couldn't remember what it was. :)

Susan

Re: Hidden Object Code

Posted: Mon Jan 30, 2012 10:07 pm
by SusanTheCat
Would people like a step by step tutorial on how to use the code?

Susan

Re: Hidden Object Code

Posted: Tue Jan 31, 2012 4:24 am
by OokamiKasumi
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.

Re: Hidden Object Code

Posted: Tue Jan 31, 2012 11:44 pm
by AERenoir
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?

Re: Hidden Object Code

Posted: Wed Feb 01, 2012 12:00 am
by OokamiKasumi
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