Unlockable imagebutton?

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.
Post Reply
Message
Author
User avatar
SweetChiel
Miko-Class Veteran
Posts: 705
Joined: Wed Jul 02, 2014 8:53 am
Completed: Nusantara: Legend of the Winged Ones
Deviantart: SweetChiel
Skype: Cecilia Susanto
Location: Indonesia
Contact:

Unlockable imagebutton?

#1 Post by SweetChiel » Thu Dec 24, 2015 6:39 pm

Hi guys, I'm a newbie ren'py programmer and I wanna know how to make an unlockable imagebuttonwhen a variable is True.

Image

I want to make a mini encyclopedia.
When a variable = True, "???" will change into an idle/hover button, and when clicked, an image will appear at the right page. (png image with info in it)

please help? >_<;
I tried with hotspot but not solved yet so I'll try my luck with image button now.

xoxo,
SweetChiel

the script at the moment:

Code: Select all

init python:
        def ency():
            hula = 0
        
        class ency2():
             a = 0
        
screen encyclopedia:

    # This ensures that any other menu screen is replaced.
    tag menu

    # The background of the main menu.
    window:
        style "mm_root"
        
      
        
        if batik: # kalau true
            imagebutton auto "menu/button_batik_%s.png" action ShowMenu('batik_test') xpos 137 ypos 206
        else: #kalau false
            imagebutton auto "menu/button_default_idle.png" xpos 137 ypos 206
        
        
        if caci: # kalau true
            imagebutton auto "menu/button_caci_%s.png" action ShowMenu('caci_test') xpos 136 ypos 237
        else: #kalau false
            imagebutton auto "menu/button_default_idle.png" xpos 136 ypos 237
        
        
        if omed: # kalau true
                imagebutton auto "menu/button_caci_%s.png" action ShowMenu('omed_test') xpos 136 ypos 272
        else: #kalau false
                imagebutton auto "menu/button_default_idle.png" xpos 136 ypos 272
        
       
        if sati: # kalau true
                imagebutton auto "menu/button_sati_%s.png" action ShowMenu("sati_test") xpos 135 ypos 308
        else: #kalau false
                imagebutton auto "menu/button_default_idle.png" xpos 135 ypos 308
        
        
        if cendrawasih: # kalau true
                imagebutton auto "menu/button_cendra_%s.png" action ShowMenu('cedrawasih_test') xpos 134 ypos 394
        else: #kalau false
                imagebutton auto "menu/button_default_idle.png" xpos 134 ypos 394
        
        
        if komodo: # kalau true
                imagebutton auto "menu/button_komodo_%s.png" action ShowMenu('komodo_test') xpos 134 ypos 427
        else: #kalau false
                imagebutton auto "menu/button_default_idle.png" xpos 134 ypos 427

        
        if garuda: # kalau true
                imagebutton auto "menu/button_garuda_%s.png" action ShowMenu('garuda_test') xpos 134 ypos 463
        else: #kalau false
                imagebutton auto "menu/button_default_idle.png" xpos 134 ypos 463

   
                    
                    
screen batik_test():
    add "Batik.png" xpos 520 ypos 1 
    tag menu
                    
screen caci_test():
    add "Caci.png" xpos 520 ypos 1
    tag menu
    
screen omed_test():
    add "Omed.png" xpos 520 ypos 1
    tag menu
    
screen sati_test():
    add "Sati.png" xpos 520 ypos 1
    tag menu
    
screen cendrawasih_test():
    add "cenderawasih.png" xpos 520 ypos 1
    tag menu

screen komodo_test():
    add "Komodo.png" xpos 520 ypos 1
    tag menu

screen garuda_test():
    add "Eagle.png" xpos 520 ypos 1
    tag menu
with those code, I got this error message:

Image

User avatar
Evildumdum
Regular
Posts: 191
Joined: Sun Jan 18, 2015 8:49 am
Projects: ApoclypseZ
Contact:

Re: Unlockable imagebutton?

#2 Post by Evildumdum » Fri Dec 25, 2015 3:50 am

I don't see any problem with your imagebuttons, though i usually define the action after the xpos and ypos. No idea if that affects it. The problem seems to be that you have not previously defined the variable Batik in an init python block. The statement if Batik: can't find a variable called Batik to reference. Check that the variable exists, is spelled exactly the same (capital letters all in the right place etc and it should work fine.

Also as a side note to your imagebuttons, give them a focus_mask. e.g.:

Code: Select all

            if x1_y10 == 2:
                imagebutton auto "buttons/nopass_%s.png" xpos 0.0335 ypos 0.0625 action ui.callsinnewcontext("button_fight0110") focus_mask True
"If at first you don't succeed, try hitting it with a shoe."

User avatar
mavyxdawn
Regular
Posts: 69
Joined: Sun Dec 20, 2015 6:18 pm
Github: mavyxdawn
itch: zeillearnings
Discord: Zeil#4950
Contact:

Re: Unlockable imagebutton?

#3 Post by mavyxdawn » Fri Dec 25, 2015 4:22 am

Try this: It's just for 2 buttons but you'll get the idea. Reference:http://www.renpy.org/doc/html/screens.h ... statements

Code: Select all

          
init:
    define batik =True     
    define caci =True
      
init python:#Global variable-can be used even outside this file
    def batikTrue():
        global batik
        batik=True
    def caciTrue():
        global batik
        caci=True
        
screen encyclopedia:
    default img =None
    window:
        style "mm_root"
        if batik: # kalau true
            imagebutton auto "menu/button_batik_%s.png"   action SetScreenVariable("img", "batik") xpos 137 ypos 206
        else: #kalau false
            imagebutton auto "menu/button_default_idle.png" xpos 137 ypos  206
            
        if caci: 
            imagebutton auto "menu/button_caci_%s.png" action SetScreenVariable("img", "caci")  xpos 137 ypos 236
        else:
            imagebutton auto "menu/button_default_idle.png" xpos 137 ypos  236
    if img:#if img is not None
        if img=="batik":
            use batik_test
        if img=="caci":
            use caci_test
            
screen batik_test():
    add "Batik.png" xpos 520 ypos 1
screen caci_test():
    add "Caci.png" xpos 520 ypos 1
I'm assuming your True/False variable is an in-game type variable(variable only available when playing) and not the persistent Data. So... If you want to change batik to True(while in the game), call the function:

Code: Select all

$batikTrue()
. If it's not an in-game var, you can just read Persistent Data and remove "init python" block. :D

philat
Eileen-Class Veteran
Posts: 1853
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Unlockable imagebutton?

#4 Post by philat » Mon Dec 28, 2015 2:14 am

Probably simpler to use If() and insensitive.

http://www.renpy.org/doc/html/screens.html#imagebutton
http://www.renpy.org/doc/html/screen_actions.html#If

Code: Select all

screen test():
    imagebutton:
        auto "appropriate_path_for_images" # the insensitive image should be the one with question marks. then idle / hover / others as appropriate
        action If(batik, ShowMenu("batik_test")) # if batik is true, the action is ShowMenu("batik_test"). If batik is false, the action is None (by default), which makes the button insensitive, which should show the question marks.
Haven't tested this, so there may be some minor errors (typos, stray quotes, etc.) but in principle, should be simple.

Post Reply

Who is online

Users browsing this forum: Google [Bot]