[SOLVED] (Display On/Off) Side Images + Menu Option Toggle

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
AvalonMelody
Regular
Posts: 30
Joined: Thu May 29, 2014 2:14 am
Projects: It's a Mystery, The Gloaming, PPYT
Organization: Sakura Cloud Games
Contact:

[SOLVED] (Display On/Off) Side Images + Menu Option Toggle

#1 Post by AvalonMelody » Tue May 22, 2018 1:47 am

Greetings!
I've been looking into side images (for game protagonist) for RenPy games and have seen mixed reviews. Some people like seeing the character they play and others prefer the character not be present (Sans game CG.)


So I was wondering, is there a way to hide/remove side images based on a menu option? Put simply, I'd like to make an option in the preferences screen that toggles the protagonist's side images (in the text box) to be displayed or not.


Quick thing to note, I'm currently using the new GUI but I can easily switch back to the old if that has a better solution!



I have seen a few forum posts like this or this , as well as cookbook pages such as this, but the latter two links' solutions confuse me and I'm not sure how to implement it. >.< (Provided that's the path to take!)

As far as I can tell (or at least, how I'm thinking it would go?) there would to be a variable (true/false?) to toggle through a menu button/option to be created in the preferences screen, but I don't know how to link it to the side image display nor keep checking if it's true/false. I guess it would have to do that each time new text is displayed in the box? If they were to turn it off in the middle of a scene that is. (Or even just right away?) Would ConditionalSwitch be used somewhere in this?

Of course, it doesn't have to be like that at all!^^;; (Maybe I need to do the transparent side image trick instead?) I'm really not sure how it would work. But if it helps in creating a solution!

Any help/tips/etc with this matter would be greatly appreciated! ^o^)/

Thank you for your time!
AvalonMelody
Last edited by AvalonMelody on Tue May 22, 2018 10:38 pm, edited 1 time in total.

kivik
Miko-Class Veteran
Posts: 784
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: (Display On/Off) Side Images + Menu Option Toggle

#2 Post by kivik » Tue May 22, 2018 3:57 am

Should be quite easy: you can edit the say screen where it shows the sideimage:

Code: Select all

screen say(who, what):
    style_prefix "say"

    window:
        id "window"

        if who is not None:

            window:
                id "namebox"
                style "namebox"
                text who id "who"

        text what id "what"


    ## If there's a side image, display it above the text. Do not display on the
    ## phone variant - there's no room.
    if not renpy.variant("small"):
        add SideImage() xalign 0.0 yalign 1.0
See the last bit with if not renpy.variant("small"):? It's checking whether it's a small screen device or not, before adding the SideImage() function (which I assume works out whether the character has a side image declared or not. So you can add a check there:

Code: Select all

    if not renpy.variant("small") and variable_here:
The variable will depend on whether you want this to be remembered across all saves, or if different saves can store different preferences. If the first, then I think you can just create your own preference variable (I could be wrong here, I've never tried it, if not you'd use a persistent variable). If the second, then you just store it as a global variable in your save, make sure you declare it with default so that it's remembered!

Let me know if that makes sense!

User avatar
AvalonMelody
Regular
Posts: 30
Joined: Thu May 29, 2014 2:14 am
Projects: It's a Mystery, The Gloaming, PPYT
Organization: Sakura Cloud Games
Contact:

Re: (Display On/Off) Side Images + Menu Option Toggle

#3 Post by AvalonMelody » Tue May 22, 2018 4:35 am

Oh wow, I didn't even think to look right in the Say screen. Shows how much I know... >o< ;; )
Thanks so much, I tested that and it works fine!

Between the cases you describe, the first is correct. I guess a persistent variable should be used? Any insight/alternative/proper-way-to-do-this would be great!
I'll take a look at how the preferences screen works though. ^^)/

Half the question answered so fast, gotta love the lemma forums and the nice community. 'u' )

kivik
Miko-Class Veteran
Posts: 784
Joined: Fri Jun 24, 2016 5:58 pm
Contact:

Re: (Display On/Off) Side Images + Menu Option Toggle

#4 Post by kivik » Tue May 22, 2018 4:56 am

Just did a quick test, preference variable doesn't save across sessions, so you'll need a persistent variable:

https://www.renpy.org/doc/html/persistent.html

The documentation doesn't have examples of how to use it for preferences, so here's what I'd do:

Code: Select all

# check if the variable exists, if not, create it
init python:
    if persistent.side_images is None:
        persistent.side_images = True

...
# inside your preferences screen, add a button:
textbutton _("Show Side Images") action [ToggleField(persistent, "side_images"), SelectedIf(persistent.side_images)]
The button uses the ToggleField() function to toggle the persistent.side_images variable between True and False. Then it uses the SelectedIf() function to declare whether the button is selected or not based on the persistent.side_images variable's value.

Alternatively you can add a condition in somewhere so that the textbutton reads "Showing Side Images" and "Hiding Side Images" as well. Make sure it doesn't read ("Show Side Images" / "Hide Side Images") as from a UX perspective it can be confusing as to whether you need to click it to make it show the side images, or it's currently showing it.

User avatar
AvalonMelody
Regular
Posts: 30
Joined: Thu May 29, 2014 2:14 am
Projects: It's a Mystery, The Gloaming, PPYT
Organization: Sakura Cloud Games
Contact:

Re: (Display On/Off) Side Images + Menu Option Toggle

#5 Post by AvalonMelody » Tue May 22, 2018 10:37 pm

Apologies for the delay in response!
Thanks so much. I've added it to the preferences screen. Works perfectly, no problems here!
I really appreciate the help. ^o^)/

Post Reply

Who is online

Users browsing this forum: TakeHomeTheCup