Page 1 of 1
How to change scenes through Variables and Screens?
Posted: Sun Jul 14, 2019 1:19 am
by Tritonials
Hello, I need to change the background using screens and variables.
Code: Select all
screen jx:
add "images/date.png" xalign 0.5 yalign 0.0
if sun == True:
$ classroom2 = 'images/classroomday.jpg'
add 'images/sun_icon.jpg' xalign 1.0 yalign 0.0
else:
$ classroom2 = 'images/clasroomnight.jpg'
add 'images/moon_icon.jpg' xalign 1.0 yalign 0.0
text "Monday" xalign 0.5 ypos 20
$ sun = True
$ classroom2 = 'images/classroomday.jpg'
image classroom = '[classroom2]'
label start:
show screen jx
scene classroom2
e "bla bla bla"
e "bla bla bla"
$ sun = False # background is now supposed to turn to night, but it doesn't.
e "It's nighttime."
return
So what I was trying to say was I need the background to also change to night when I set the variable "sun" to False and
that activates the background and my sun icon to change. However, The background doesn't change but the sun icon does. I tried everything I learned from Ren'Py and python and honestly this is my last choice so please any help would be kindly appreciated.

Re: How to change scenes through Variables and Screens?
Posted: Sun Jul 14, 2019 2:06 am
by Per K Grok
Tritonials wrote: ↑Sun Jul 14, 2019 1:19 am
Hello, I need to change the background using screens and variables.
Code: Select all
screen jx:
add "images/date.png" xalign 0.5 yalign 0.0
if sun == True:
$ classroom2 = 'images/classroomday.jpg'
add 'images/sun_icon.jpg' xalign 1.0 yalign 0.0
else:
$ classroom2 = 'images/clasroomnight.jpg'
add 'images/moon_icon.jpg' xalign 1.0 yalign 0.0
text "Monday" xalign 0.5 ypos 20
$ sun = True
$ classroom2 = 'images/classroomday.jpg'
image classroom = '[classroom2]'
label start:
show screen jx
scene classroom2
e "bla bla bla"
e "bla bla bla"
$ sun = False # background is now supposed to turn to night, but it doesn't.
e "It's nighttime."
return
So what I was trying to say was I need the background to also change to night when I set the variable "sun" to False and
that activates the background and my sun icon to change. However, The background doesn't change but the sun icon does. I tried everything I learned from Ren'Py and python and honestly this is my last choice so please any help would be kindly appreciated.
Try this
Code: Select all
screen jx:
add "images/date.png" xalign 0.5 yalign 0.0
if sun == True:
add 'images/sun_icon.jpg' xalign 1.0 yalign 0.0
else:
add 'images/moon_icon.jpg' xalign 1.0 yalign 0.0
text "Monday" xalign 0.5 ypos 20
default sun = True
image classroom2 = 'images/classroomday.jpg'
image classroom = 'images/clasroomnight.jpg'
label start:
show screen jx
scene classroom2
e "bla bla bla"
e "bla bla bla2"
$ sun = False
scene classroom
e "It's nighttime."
return
Re: How to change scenes through Variables and Screens?
Posted: Sun Jul 14, 2019 3:41 am
by IrinaLazareva
Code: Select all
default sun = True
layeredimage classroom:
if sun:
'classroomday.jpg'
else:
'clasroomnight.jpg'
screen jx:
add "date.png" xalign 0.5 yalign 0.0
if sun:
add 'sun_icon.jpg' xalign 1.0 yalign 0.0
else:
add 'moon_icon.jpg' xalign 1.0 yalign 0.0
text "Monday" xalign 0.5 ypos 20
label start:
show screen jx
scene classroom
e "bla bla bla"
e "bla bla bla"
$ sun = False # background is now supposed to turn to night.
e "It's nighttime."
return
https://renpy.org/doc/html/layeredimage ... red-images
https://renpy.org/doc/html/layeredimage.html#if
Re: How to change scenes through Variables and Screens?
Posted: Sun Jul 14, 2019 4:33 am
by Remix
In my experience, the easiest approach is to use a string value in your variable and interpolate it in the image (thus automatically making it dynamic)
Code: Select all
default time_of_day = "day" # or "night" or whatever
image classroom = "images/clasroom[time_of_day].jpg"
image sun_moon_icon = "images/[time_of_day]_icon.jpg"
label start:
scene classroom
"..."
$ time_of_day = "night"
"..."
Re: How to change scenes through Variables and Screens?
Posted: Mon Jul 15, 2019 3:35 pm
by Crazy Li
I also do what Remix said as much as possible, making my variable values match something in my file names. Fitted specifically to the OP example, I think it would be fashioned something like...
Code: Select all
screen jx:
add "images/date.png" xalign 0.5 yalign 0.0
add "images/[time]_icon.jpg" xalign 1.0 yalign 0.0 # you will need your icons to be day_icon.jpg and night_icon.jpg instead for this to work
text "Monday" xalign 0.5 ypos 20
$ time = "day"
image classroom = "images/classroom[time].jpg"
label start:
show screen jx
scene classroom
e "bla bla bla"
e "bla bla bla"
$ time = "night"
e "It's nighttime."
return