How to select different photo sets based on a question.

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
Insane33
Newbie
Posts: 6
Joined: Fri Feb 11, 2022 3:50 pm
Contact:

How to select different photo sets based on a question.

#1 Post by Insane33 »

Hello All,

I am having a problem with image set selections. In the game I am writing I am offering players the choice to play as a Black Male with his primary interest being a white woman and her daughter or to play as a White man with his primary in being a Black woman and her daughter. I set up my gallery and images and attempted to use an if/else statement to select between the image sets.

My overall goal is to create a faster way to select images without having to code if/else statements before every image shown in the game. Therefore, I set up folders and named the images the same hoping that a couple of if/else statements would be enough to select a group of photos based on the folder where they reside. The game engine is selecting the wrong pictures, wrong side image, and is using the 'eileen' placeholder photo instead of the "Ryan_fake1.jpg"

The images are just placeholders until I get to rendering the images that will live in the game.

Right now, when I run the game it is stuck on Black MFC regardless of the choice made in the beginning.

This snippet of code is from my script.rpy

menu:
"Black Man/White Female Character and Family":
$ skintone = True
"White Man/Black Female Character and Family":
$ skintone = False

This snippet of code is from my images.rpy.

if skintone == True:

image ryan_fake1 = ("Ryan/White_Ryan/Ryan_fake1.jpg")

image imgir1 = MaxScale("Rewards/w_mfc_reward/gallery00.jpg")
image imgir1b = MaxScale("Rewards/w_mfc_reward/intro_reward1.jpg")
image imgir1c = MaxScale("Rewards/w_mfc_reward/intro_reward2.jpg")
# Thumbs for White MFC
image thumb0 = MinScale("Rewards/w_mfc_reward/gallery00.jpg", maxthumbx, maxthumby)

else:
# Black MFC reward photos and Gifs

image ryan_fake1 = ("Ryan/Black_Ryan/ryan_fake1.jpg")

image imgir1 = MaxScale("Rewards/b_mfc_reward/gallery00.jpg")
image imgir1b = MaxScale("Rewards/b_mfc_reward/intro_reward1.jpg")
image imgir1c = MaxScale("Rewards/b_mfc_reward/intro_reward2.jpg")
# Thumbnails for Black MFC
image thumb0 = MinScale("Rewards/b_mfc_reward/gallery00.jpg", maxthumbx, maxthumby)

if skintone == True:
image ryan:
"Ryan/White_Ryan/ryan.jpg"
size(200,200)

image side ryan:
LiveCrop((0,0,250,250,), "ryan")

else:
image ryan:
"Ryan/Black_Ryan/ryan.jpg"
size(250,250)

image side ryan:
LiveCrop((0,0,250,250,), "ryan")

if skintone == True:
image ben:
"MC/Black_MC/ben.jpg"
size(200,206)

image side ben:
LiveCrop((0,0,250,250,), "ben")

else:
image ben:
"MC/White_MC/ben.jpg"
size(250,250)

image side ben:
LiveCrop((0,0,250,250,), "ben")

transform same_transform(old, new):
old
new with Dissolve(0.2, alpha=True)

define config.side_image_same_transform = same_transform

define config.say_attribute_transition = Dissolve(0.2, alpha=True)

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

Re: How to select different photo sets based on a question.

#2 Post by Ocelot »

Images are defined in init time. Before game starts. Before main menu appears. Before splashscreen. Obviously your variables would not exist then (and actually your conditions are not even checked, since they are not in init block)

What you can do, is to make your images a ConditionSwitch, which will select nessesary image based on variable value.
https://www.renpy.org/doc/html/displaya ... tionSwitch

Code: Select all

image ben = ConditionSwitch(
    "skintone", "MC/Black_MC/ben.jpg",
    "True", "MC/White_MC/ben.jpg"
)
< < insert Rick Cook quote here > >

Insane33
Newbie
Posts: 6
Joined: Fri Feb 11, 2022 3:50 pm
Contact:

Re: How to select different photo sets based on a question.

#3 Post by Insane33 »

Thanks for the response. They are defined in my script.rpy. The code from above was partly from my script.rpy, the rest was from images.rpy. All my variables are defined prior to the first question in the game. I had to remove the MaxScale/MinScale arguments, the maxthumbx/y, and substitute the variables using this code, removing also the if/else statements. I will have to resize my thumbnails and standardize the size of images, but it should be faster at that point anyway. These are all just placeholders until I start attempting to create the actual images and animations for the game.

script.rpy file

label start:

# several misc. variables then these three at the end. This happens just before the "label start1:". I did this because there are instances where if you make enough bad choices the game forces a restart and I need the variables back to their original state, either True, False, or = 0, for most of the variables. I never saw anything similar to this in an init: block, so I didn't think it was necessary.

# These variables are for calling the correct images from the correct folders. I named the images the same within the different folders to cut down on how much coding I would need to do. By the end of the first 4 chapters of the game (Part 1 of the game), 26,000 words of text and dialog, over 1000 images, rewards, and around 10-15 achievement badges, plus nearly 100 animations, I am guessing on that, but it will be close. I am still very early in this process.

default choosemfc = "White_Ryan"
default choosemfc2 = "w_mfc_reward"
default choosemc = "Black_MC"

# if during the question regarding skin tone choice the player chooses the non-canon skin tone, those variables change to "Black, b_mfc_reward, and White". I wrote this as a story, then decided to try turning it into a game.

label start1:

#I also had to use

show imgir1 with dissolve #to show the correct image and keep the compiler from getting confused, for lack of a better term. Now it calls all the correct images in both instances.

in images.rpy

# MFC Images

image Ryan_fake1 = ("Ryan/[choosemfc]/Ryan_fake1.jpg")

#reward images

image imgir1 = ("Rewards/[choosemfc2]/intro_reward.jpg")
image imgir1b = ("Rewards/[choosemfc2]/intro_reward1.jpg")
image imgir1c = ("Rewards/[choosemfc2]/intro_reward2.jpg")

# thumbnails

image thumb0 = ("Rewards/[choosemfc2]/intro_reward.jpg")

# side images

image ryan:
"Ryan/[choosemfc]/ryan.jpg"
size(200,200)

image side ryan:
LiveCrop((0,0,250,250,), "ryan")

image ryan:
"Ryan/[choosemfc]/ryan.jpg"
size(250,250)

image side ryan:
LiveCrop((0,0,250,250,), "ryan")

image ben:
"MC/[choosemc]/ben.jpg"
size(200,206)

image side ben:
LiveCrop((0,0,250,250,), "ben")

image ben:
"MC/[choosemc]/ben.jpg"
size(250,250)

image side ben:
LiveCrop((0,0,250,250,), "ben")

I will take a look at the "condition" argument for later use, it may speed up the process for certain things.

Thanks

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

Re: How to select different photo sets based on a question.

#4 Post by Ocelot »

Dynamic images (with variable substitution within them) would work too, yes.

One thing about default statements: those are implicitely executed at init time, so it does not matter, where you place them (commongly they are placed outside any labels to avoid confusion). Depending on how "restart" is done, it might or might not work. If you restart by throwing player in main menu, where he can start new game, it would work. If you just jump to start, they would not be reset to initial values.
< < insert Rick Cook quote here > >

Insane33
Newbie
Posts: 6
Joined: Fri Feb 11, 2022 3:50 pm
Contact:

Re: How to select different photo sets based on a question.

#5 Post by Insane33 »

I take that to mean that since I did jump to start that I would have to use an init: block and define the variables instead of using default?

I guess I do need one variable not changed the $ restart += 1 variable. It determines how many times a player has restarted from within the game. It then calls a question of whether or not the player wants to replay the introduction or skip to chapter 1. Nothing from the introduction carries over into the game.

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

Re: How to select different photo sets based on a question.

#6 Post by Ocelot »

Insane33 wrote: Wed Feb 16, 2022 9:55 am I take that to mean that since I did jump to start that I would have to use an init: block and define the variables instead of using default?
On the contrary. Anything inside of init block, and all implicitely init statements (default, define, image, etc) will be executed exactly once before game even starts. If you jump to the beginning, those statement will not be executed again. Example:

Code: Select all

label start:
    default x = 0
    "x = [x]"
    $ x += 1
    jump start
will print:

Code: Select all

x = 0
x = 1
x = 2
...
because default statement will only be executed during RenPy initialization.
What you want, is to reset your variables in normal Python blocks.

Code: Select all

# setting default values, so they would be set if
# loading previous version of the game, where they didn't existed
default x = 0
default y = 0

label restart: # resetting to the default values
    python:
        x = 0
        y = 0
    jump start 

label start:
    # ... code of the game
    if # ...
        jump restart # restarts the game
        
# or even:
label start:
    # no default, no define, simply assign variables their values here
    $ x = 0
    python:
        y = 0
        
     # code of the game
    if # ...
        jump start # restarts the game
< < insert Rick Cook quote here > >

Insane33
Newbie
Posts: 6
Joined: Fri Feb 11, 2022 3:50 pm
Contact:

Re: How to select different photo sets based on a question.

#7 Post by Insane33 »

I believe I understand. To save on coding, I can remove the word "default" and replace it with "$" and simply assign the variables. At the beginning of my code after the first start label.

label start:

$ x = 0
$ y = True
$ z = False

and so on or do it in python. It is a lot of variables so if this works it will be much more expedient.

Post Reply

Who is online

Users browsing this forum: No registered users