screen action Show() choosing one from a list of screens?

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
searchwindows
Regular
Posts: 86
Joined: Wed Dec 15, 2021 6:17 pm
Contact:

screen action Show() choosing one from a list of screens?

#1 Post by searchwindows »

I'd be thankful if someone could lead me in the right direction with this.

I have a clickable phone display; screen phone_home: with an imagebutton "change_phone_bg".

I'd like to be able to click on that imagebutton to change the background image of the phone from a list of let's say, 5 background images. [bg1,bg2,bg3,bg4,bg5]

I also need the chosen bg to stay as the bg on all phone screens, like on phone_settings screen and phone_messages screen. Then if I were to change the bg again, I need the change to be implemented to other phone screens as well.

This is how I have it set up:

Code: Select all

1 screen phone_home:
2	add "bg0"    ### So I need this line to change to bg1,bg2,bg3,bg4 or bg5 when I change the bg with imagebutton on line 12.
3	
4	imagebutton auto "images/phone/message_icon.png":
5	focus_mask True 
6	action Show("message")
7	
8	imagebutton auto "images/phone/settings_icon.png":
9	focus_mask True 
10	action Show("settings")
11
12	imagebutton auto "images/phone/change_phone_bg.png":
13	focus_mask True
14	action(?????) ## How to make it so that bg1~bg5 is shown one by one so the player can choose.
15
16 screen message:
17	
18
19 screen settings:

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: screen action Show() choosing one from a list of screens?

#2 Post by Ocelot »

Code: Select all

define backgrounds = ["bg0", "bg1", "bg2", "bg3", "bg4", "bg5"]
default bg_index = 0

init python:
    def next_background:
        store.bg_index += 1
        if store.bg_index == len(store.backgrounds):
            store.bg_index = 0

screen phone_home():
    add backgrounds[bg_index]

    imagematton auto "..." action Function(next_background)
< < insert Rick Cook quote here > >

searchwindows
Regular
Posts: 86
Joined: Wed Dec 15, 2021 6:17 pm
Contact:

Re: screen action Show() choosing one from a list of screens?

#3 Post by searchwindows »

Ocelot wrote: Sat Jan 08, 2022 3:23 am

Code: Select all

define backgrounds = ["bg0", "bg1", "bg2", "bg3", "bg4", "bg5"]
default bg_index = 0

init python:
    def next_background:
        store.bg_index += 1
        if store.bg_index == len(store.backgrounds):
            store.bg_index = 0

screen phone_home():
    add backgrounds[bg_index]

    imagematton auto "..." action Function(next_background)
thank you! But I'm getting invalid syntax error on

Code: Select all

def next_background:

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: screen action Show() choosing one from a list of screens?

#4 Post by Ocelot »

Oh, my bad, it should be def next_background():
< < insert Rick Cook quote here > >

searchwindows
Regular
Posts: 86
Joined: Wed Dec 15, 2021 6:17 pm
Contact:

Re: screen action Show() choosing one from a list of screens?

#5 Post by searchwindows »

Ocelot wrote: Sun Jan 09, 2022 3:31 am Oh, my bad, it should be def next_background():
Thank you!
Everything works as intended but the bg image resets back to bg0 after saving and loading back.
How can I make it stay the one you've chosen?

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: screen action Show() choosing one from a list of screens?

#6 Post by Ocelot »

It should not do that. Did you make any changes to code? Especially notice that both define and default are used.
< < insert Rick Cook quote here > >

searchwindows
Regular
Posts: 86
Joined: Wed Dec 15, 2021 6:17 pm
Contact:

Re: screen action Show() choosing one from a list of screens?

#7 Post by searchwindows »

Ocelot wrote: Thu Jan 13, 2022 3:19 am It should not do that. Did you make any changes to code? Especially notice that both define and default are used.
The only changes I made are the name of the variables to my liking.

This is what I have:

Code: Select all

screen phone_home():
    modal True
    add phone_bgs[bg_index]
    ##Settings button
    imagebutton auto "images/phone/settings_%s.png":
         focus_mask True
         action [Show("phone_settings"), Hide("phone_home")]
         
define phone_bgs = ["bg0","sbg1", "sbg2", "ebg1", "ebg2", "kbg1"]
default bg_index = 0
init python:
    def next_bg():
        store.bg_index += 1
        if store.bg_index == len(store.phone_bgs):
            store.bg_index = 0

screen phone_settings():
    add phone_bgs[bg_index]
	## button for bg change
    imagebutton auto "images/phone/settings_bgchoose_%s.png":
        focus_mask True
        action Function(next_bg)
        ##button to return back to phone home screen. 
    imagebutton auto "images/phone/return1_%s.png":
         focus_mask True
         action [Show("phone_home"), Hide("phone_settings")]

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: screen action Show() choosing one from a list of screens?

#8 Post by Ocelot »

So, what are you doing exactly?

My assumption is that you open your phone, click "next background" several times, immideately save then load.
In that case the problem you have is that RenPy saves state on checkpoints. For example, if you were to close your phone screen and advance dialogue, then it will save, since you hit a checkpoint.
Depending on how your game is structured, you might need to use retain_after_load or checkpoint
https://www.renpy.org/doc/html/save_loa ... after-load

Another discussion on this topic: viewtopic.php?t=30752
< < insert Rick Cook quote here > >

searchwindows
Regular
Posts: 86
Joined: Wed Dec 15, 2021 6:17 pm
Contact:

Re: screen action Show() choosing one from a list of screens?

#9 Post by searchwindows »

Ocelot wrote: Thu Jan 13, 2022 2:59 pm So, what are you doing exactly?

My assumption is that you open your phone, click "next background" several times, immideately save then load.
In that case the problem you have is that RenPy saves state on checkpoints. For example, if you were to close your phone screen and advance dialogue, then it will save, since you hit a checkpoint.
Depending on how your game is structured, you might need to use retain_after_load or checkpoint
https://www.renpy.org/doc/html/save_loa ... after-load

Another discussion on this topic: viewtopic.php?t=30752
You're right. It saved after a dialogue. I think that's plenty enough. Thanks as always

Post Reply

Who is online

Users browsing this forum: No registered users