[SOLVED]NSFW and Gore toggles

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
StormyThunder
Newbie
Posts: 10
Joined: Wed Aug 23, 2023 6:09 pm
Projects: Working solo on "Afterlife Feels" and its written novel.
itch: stormythunder
Discord: Huh#7134
Contact:

[SOLVED]NSFW and Gore toggles

#1 Post by StormyThunder »

I have asked around since yesterday if anyone could help (Ren'py discord and reddit) but none of the code given seems to work. I've been told that half of my code is good, so I won't post that in case someone wants to look at it, but it's this one part that I can't figure out:

Code: Select all

default persistent.nsfw_enabled = True
default persistent.gore_enabled = True

label nsfw_scene:
    if persistent.nsfw_enabled:
        show expression "images/nsfw/bg3v3[nsfw].png"
    else:
        show expression "images/sfw/bg3v3[sfw].png"
I get no error messages at any point, and the buttons for both NSFW and Gore do show up (only code for NSFW is here because I don't have gore scenes yet), but the images never change to their sfw versions when the button is toggled to off.
Last edited by StormyThunder on Tue Aug 29, 2023 4:54 pm, edited 1 time in total.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1057
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: NSFW and Gore toggles

#2 Post by m_from_space »

I don't know what your code is about, so here is what comes to mind:

Do your filenames include brackets like you have inside the string? Don't do that! Or are "nsfw" and "sfw" some kind of variables you like to include there?

Code: Select all

label nsfw_scene:
    if persistent.nsfw_enabled:
        show expression "images/nsfw/bg3v3_nsfw.png"
    else:
        show expression "images/sfw/bg3v3_sfw.png"
For the changes of a button to apply, the label would have to be called again of course. I mean that's obvious, I am just saying. Not sure what you mean by "but the images never change".

User avatar
StormyThunder
Newbie
Posts: 10
Joined: Wed Aug 23, 2023 6:09 pm
Projects: Working solo on "Afterlife Feels" and its written novel.
itch: stormythunder
Discord: Huh#7134
Contact:

Re: NSFW and Gore toggles

#3 Post by StormyThunder »

m_from_space wrote: Tue Aug 29, 2023 9:25 am I don't know what your code is about, so here is what comes to mind:

Do your filenames include brackets like you have inside the string? Don't do that! Or are "nsfw" and "sfw" some kind of variables you like to include there?

Code: Select all

label nsfw_scene:
    if persistent.nsfw_enabled:
        show expression "images/nsfw/bg3v3_nsfw.png"
    else:
        show expression "images/sfw/bg3v3_sfw.png"
For the changes of a button to apply, the label would have to be called again of course. I mean that's obvious, I am just saying. Not sure what you mean by "but the images never change".
The images include "nsfw" and "sfw" in their file names (without brackets) but I was suggested to use the brackets. I obviously don't think they work but nsfw and sfw are supposed to be variables. I put the two images in separate folders labeled "nsfw" and "sfw", which I was also told was okay to do. Do I remove nsfw and sfw from the ends of the images and leave both as "bg3v3" in the two folders?
I toggle "nsfw" off in the game's settings and it never changes to the sfw version, which is why I'm posting. Do you need the other part of the code? Again, I was told the other code was good, but just if you want to look at it.

Edit: I think I figured something out but I'm not too sure what else to do.
So if I put this right before the image:

Code: Select all

label nsfw_scene:
    if persistent.nsfw_enabled:
        show expression "images/nsfw/bg3v3"
    else:
        show expression "images/sfw/bg3v3" 

Then it will say either the nsfw image or sfw image isn't found, depending on if nsfw is off or on.
I'm looking into why that is right now.

Edit 2: I HAVE FIGURED IT OUT, THANK YOU FOR POINTING OUT THE BRACKETS! I just had to put .png after the image names and it works!

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1057
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: NSFW and Gore toggles

#4 Post by m_from_space »

StormyThunder wrote: Tue Aug 29, 2023 3:29 pmThe images include "nsfw" and "sfw" in their file names (without brackets) but I was suggested to use the brackets. I obviously don't think they work but nsfw and sfw are supposed to be variables.
I think that was a misunderstanding when people told you so. But don't use brackets inside filenames to begin with, since Renpy looks for brackets inside strings to determine whether or not it should include the contents of a variable there.

Also make sure to be precise about what you are talking about, your words are a bit confusing. In your code snippets you mention only a single variable called "nsfw_enabled", which is stored inside the persistent object. They are no variables called "nsfw" or "sfw".
Do I remove nsfw and sfw from the ends of the images and leave both as "bg3v3" in the two folders?
You don't have to at all. It doesn't matter how you name them, just don't use brackets. I wouldn't give them the same filename on the other hand, because Renpy checks for every image in your image folders and creates a variable for it. So files with the same name cannot be properly addressed with those variables later on. Naming them with an underscore like I suggested is recommended.

Post Reply

Who is online

Users browsing this forum: Directony, Google [Bot]