Using imagebutton to call a stat screen

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
lydia
Newbie
Posts: 12
Joined: Sat Jul 07, 2012 11:38 pm
Contact:

Using imagebutton to call a stat screen

#1 Post by lydia »

I'm trying to use an image button of a journal on the main screen, that when clicked, opens up a new screen that has character stats. I use the following to create the journal image button:
screen mapview:
vbox xalign 0.5 yalign 0.02:
imagebutton:
idle "gui/diary_idle.png"
hover "gui/diary_hover.png"
action ui.callsinnewcontext("aff_screen_label")

I use the following to create the character stat screen:
screen aff_screen:
tag menu
default ch_bio = "none"
$ corr_name = "None"
frame:

xmaximum 0
ymaximum 0
#xanchor 0.5
#yanchor 0.5
#xalign 0.5
#yalign 0.5
#xpos 0.5
#ypos 0.5
image "gui/journal.png" at Position(xaling = 0.5, yaling=0.5)
xoffset -2
yoffset -4
hbox:
vbox:
xoffset 60
yoffset 35
xsize 580

text "{font=DejaVuSans.ttf}{color=#000000}{size= 36}Journal{/size}{/color}{/font}" at center

hbox:
yoffset 15
imagebutton:
idle "gui/julia.png"
hover "gui/julia_hl.png"
action SetScreenVariable("ch_bio", "celia")

vbox:
xoffset 150
yoffset -125
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Name: Julia {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Lust: [julia_lust] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Love: [julia_love] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Hotness: [julia_hot] {/size}{/color}{/font}"

hbox:
yoffset 15
imagebutton:
idle "gui/lincy.png"
hover "gui/lincy_hl.png"
action SetScreenVariable("ch_bio", "celia")

vbox:
xoffset 150
yoffset -125

text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Name: Lincy {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Lust: [lincy_lust] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Love: [lincy_love] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Hotness: [lincy_hot] {/size}{/color}{/font}"

hbox:
yoffset 15
imagebutton:
idle "gui/lincy.png"
hover "gui/lincy_hl.png"
action SetScreenVariable("ch_bio", "celia")

vbox:
xoffset 150
yoffset -125

text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Name: Lincy {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Lust: [lincy_lust] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Love: [lincy_love] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Hotness: [lincy_hot] {/size}{/color}{/font}"

hbox:
yoffset 5
textbutton "Return" action Return()
null width 400

hbox:
xoffset 500
yoffset -830
imagebutton:
idle "gui/lincy.png"
hover "gui/lincy_hl.png"
action SetScreenVariable("ch_bio", "celia")

vbox:
xoffset 700
yoffset -970

text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Name: Lincy {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Lust: [lincy_lust] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Love: [lincy_love] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Hotness: [lincy_hot] {/size}{/color}{/font}"

label aff_screen_label:
call screen aff_screen

I've had to place the aff info in the script because I kept getting an error message when I tried to call the screen. The player uses the return on the stat screen to return to the main screen. Renpy then wants a new command to continue. I placed a jump to the next action. However, renpy uses this jump every time the journal is consulted and creates a loop. How do I prevent the loop? Also, is there a better way to code this for an image button to call a stat screen? Thanks for your help.

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Using imagebutton to call a stat screen

#2 Post by Alex »

What's the error you got when calling aff_screen using screen action in mapview screen?
Also, check this sample - viewtopic.php?f=8&t=53959#p505785

lydia
Newbie
Posts: 12
Joined: Sat Jul 07, 2012 11:38 pm
Contact:

Re: Using imagebutton to call a stat screen

#3 Post by lydia »

Alex wrote: Sat Mar 30, 2019 5:01 am What's the error you got when calling aff_screen using screen action in mapview screen?
Also, check this sample - viewtopic.php?f=8&t=53959#p505785
I only receive the error when I don't have the label aff_screen coding in the script file. I was try to put the aff_screen info in its' own file and call it from the script file. The error is that renpy can't find the label aff_screen. Thanks for your reply and the link to the character bio post. I'll work through the posts so I call follow the bio screen setup.

The issue that I'm having comes after I've called the journal,the player has clicked on the journal to see the character stats, and clicked the return button to leave the stats screen and returns to the main screen. The code calls for the player to go home. Then to play some games. After this, a jump is called to start the next day. However, renpy doesn't advance to day two. I'm left with only the main screen. And if I click on the journal imagebutton, it replays the text from the jump home and playing games again until I'm left with the empty main screen again. The code below starts with the calling of the aff screen:

label aff_screen_label:
call screen aff_screen

jump home

return

label home:
scene bedroom
show screen hud
"Finally, the school day is over."
jump games

label games:
scene bedroom
"Time to unwind playing the game that came with my new computer."
jump day_two

label day_two:
show screen hud
call screen mapview
call screen aff_screen
scene bedroom
"A new day."


I'm left in a loop and can't get to day 2 but can't see what I need to fix it. Also, I'm wanting the player to be able to consult the journal at any time. How do I prevent renpy from replaying the code immediately after the last time the player presses the journal imagebutton? Hopefully I've posted the info necessary to follow my questions. Please let me know if I've missed something. Thanks for the help.

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Using imagebutton to call a stat screen

#4 Post by Alex »

Well, when you "call" a screen it must "return" a value, so in mapview screen must be a button with action Return("smth") to let player progress the game.
https://www.renpy.org/doc/html/screens.html#call-screen

If you want to show a journal screen and don't let player progress untill this screen beign closed, then set modal property to a screen - https://www.renpy.org/doc/html/screens. ... -statement

lydia
Newbie
Posts: 12
Joined: Sat Jul 07, 2012 11:38 pm
Contact:

Re: Using imagebutton to call a stat screen

#5 Post by lydia »

Sorry for not following you. I've revised the mapview code that I use create the diary imagebutton to the following:
screen mapview:
vbox xalign 0.5 yalign 0.02:
imagebutton:
idle "gui/diary_idle.png"
hover "gui/diary_hover.png"
action Show( "aff_screen" )

I've changed the aff screen code to include:
modal True

When I call the mapview code, it shows the diary imagebutton and the game comes to a halt due to the missing action return in mapview if I'm following your post. I believe the return action is in the aff screen code:
textbutton "Return" action Hide( "aff_screen" ).

When I click the return button in the aff screen it closes the aff screen and the game resumes. I've been unable to determine how to add an action return for the situation in which I call for the mapview but the player decides they don't want to click on the diary to see the character stats. I added "return" to the bottom of the mapview code but it didn't work. The game still works but I'm trying to learn how to code properly. Thanks for your kind assistance in dealing with a newbie.

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Using imagebutton to call a stat screen

#6 Post by Alex »

I mean, for your return button you need to use action Return("some_value_maybe") - https://www.renpy.org/doc/html/screen_a ... tml#Return

lydia
Newbie
Posts: 12
Joined: Sat Jul 07, 2012 11:38 pm
Contact:

Re: Using imagebutton to call a stat screen

#7 Post by lydia »

Sorry but still no following how to correct. The mapview code only brings up the imagebutton. Until the imagebutton is pressed the game is on hold. Pressing the imagebutton goes to the screen that has a return button that takes the player back to the game. I tried to add a return action to the mapview code but I couldn't get it to work. It didn't take "Return". If I add a return code to the mapview, will it prevent the image button from bring up the stat screen? The current code only adds one click to the imagebutton but am trying to provide this as an option for the player. Thanks.

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Using imagebutton to call a stat screen

#8 Post by Alex »

So, how the actual code looks for now?

lydia
Newbie
Posts: 12
Joined: Sat Jul 07, 2012 11:38 pm
Contact:

Re: Using imagebutton to call a stat screen

#9 Post by lydia »

Code I use to call the imagebutton:
call screen mapview

The mapview code is as follows:
screen mapview:
vbox xalign 0.5 yalign 0.02:
imagebutton:
idle "gui/diary_idle.png"
hover "gui/diary_hover.png"
action Show( "aff_screen" )

Renpy then waits for the player to click the journal. Not a huge deal of course as it is just one click. But each time after I hide the journal, they'll need to click it agin when I call for the mapview. I tried return and return("aff_screen") but these didn't work.

The aff_screen is as follows:
screen aff_screen:
tag menu
modal True
default ch_bio = "none"
$ corr_name = "None"
frame:

xmaximum 0
ymaximum 0
#xanchor 0.5
#yanchor 0.5
#xalign 0.5
#yalign 0.5
#xpos 0.5
#ypos 0.5
image "gui/journal.png" at Position(xaling = 0.5, yaling=0.5)
xoffset -2
yoffset -4
hbox:
vbox:
xoffset 60
yoffset 35
xsize 580

text "{font=DejaVuSans.ttf}{color=#000000}{size= 36}Journal{/size}{/color}{/font}" at center

hbox:
yoffset 15
imagebutton:
idle "gui/julia.png"
hover "gui/julia_hl.png"
action SetScreenVariable("ch_bio", "celia")

vbox:
xoffset 150
yoffset -125
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Name: Julia {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Lust: [julia_lust] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Love: [julia_love] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Hotness: [julia_hot] {/size}{/color}{/font}"

hbox:
yoffset 15
imagebutton:
idle "gui/lincy.png"
hover "gui/lincy_hl.png"
action SetScreenVariable("ch_bio", "celia")

vbox:
xoffset 150
yoffset -125

text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Name: Lincy {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Lust: [lincy_lust] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Love: [lincy_love] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Hotness: [lincy_hot] {/size}{/color}{/font}"

hbox:
yoffset 15
imagebutton:
idle "gui/britt.png"
hover "gui/britt_hl.png"
action SetScreenVariable("ch_bio", "celia")

vbox:
xoffset 150
yoffset -125

text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Name: Britt {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Lust: [britt_lust] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Love: [britt_love] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Hotness: [britt_hot] {/size}{/color}{/font}"

hbox:
yoffset 5
textbutton "Return" action Return()
null width 400

hbox:
xoffset 500
yoffset -830
imagebutton:
idle "gui/halia.png"
hover "gui/halia_hl.png"
action SetScreenVariable("ch_bio", "celia")

vbox:
xoffset 700
yoffset -970

text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Name: Halia {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Lust: [halia_lust] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Love: [halia_love] {/size}{/color}{/font}"
null height 10
text "{font=DejaVuSans.ttf}{color=#000000}{size= 20}Hotness: [halia_hot] {/size}{/color}{/font}"

hbox:
yoffset 100
# This will close the screen and let the game continue
# exactly where he were before the screen show up.
textbutton "Return" action Hide( "aff_screen" )

label aff_screen_label:
show screen aff_screen

Once the player clicks the imagebutton, the aff_screen appears to show character stats. At the bottom of the character stat screen is the textbutton that returns the player to the main screen. I wondering if there is a way to add a return to the main screen after calling the mapview screen without requiring the player to click on the journal. But I do want the journal to remain available to be clicked so players can consult the character stats when they need to. Thanks again for your patience.

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Using imagebutton to call a stat screen

#10 Post by Alex »

Is this functionality you want?

Code: Select all

screen main_scr():
    frame:
        align (0.5, 0.05)
        vbox:
            textbutton "Show bio screen" action Show("bio_scr") # shows the other screen
            null height 10 
            textbutton "Return" action Return() # returns to the game, since screen was "called" (not shown)
        
screen bio_scr():
    modal True # make the other screens inactive
    
    frame:
        align (0.5, 0.5)
        vbox:
            text "Some text"
            null height 10
            textbutton "Close" action Hide("bio_scr") # hides screen


# The game starts here.

label start:
    "..."
    call screen main_scr # the game will wait until this screen return something
    "... ... ..."
    "?!"

lydia
Newbie
Posts: 12
Joined: Sat Jul 07, 2012 11:38 pm
Contact:

Re: Using imagebutton to call a stat screen

#11 Post by lydia »

Thank you so much for your reply and detailed coding. I inserted your code into my game, I think correctly. Your change to the main_scr coding does give the player the option to see the screen bio or to return and close the main scr as I asked about. If the player does click on the show bio screen textbutton it shows the bio screen and they select close to close the bio screen. However, the game won't continue until the main scr is closed, so the player needs to select return which removes the main scr textbutton. What I'm wondering is if the main scr textbutton can remain on the screen, yet still allow the player to continue the game. This way they can select to click the textbutton to look at the bio screen whenever they like. With my current coding, the main scr & bio screen are only available when I call the screens. Sorry I wasn't clear on what I was trying to do in my prior posts.

User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Using imagebutton to call a stat screen

#12 Post by Alex »

If you need main_scr to be always onscreen then just "show" this screen, not "call" it. And don't hide it...

https://www.renpy.org/doc/html/screens. ... statements

lydia
Newbie
Posts: 12
Joined: Sat Jul 07, 2012 11:38 pm
Contact:

Re: Using imagebutton to call a stat screen

#13 Post by lydia »

Thank you so much! This is just what I was looking for.

Post Reply

Who is online

Users browsing this forum: No registered users