"add" with dissolve

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
recreation
Regular
Posts: 42
Joined: Sun Jul 01, 2018 8:32 am
Contact:

"add" with dissolve

#1 Post by recreation » Sat Aug 20, 2022 6:36 am

I'm a bit stumped, I have a screen with buttons that change the background of the screen depending on variables. It's a simple toggle between first person and third person.

Code: Select all

screen povscreen():
    if campov:
        add pov1
        imagebutton auto "switch_cam1_%s.png" action [ ToggleVariable("campov", true_value=True,false_value=False)] yalign .01 xalign .99 at btnzoom
    else:
        add pov2
        imagebutton auto "switch_cam2_%s.png" action [ ToggleVariable("campov", true_value=True,false_value=False)] yalign .01 xalign .99 at btnzoom
The added "images" are mostly movies, and I change them several times outside of the screen during normal dialogue (via variables).
I know I can use a transition on the screen itself, but I want to avoid calling/showing the screen every time I change the image variable, so a transition on the "add" would be the best solution.
The problem is that with "add" I can't use the "on show" and "on hide" functions, which is the only way I can think of to make a working dissolve

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: "add" with dissolve

#2 Post by Alex » Sat Aug 20, 2022 7:39 am

recreation wrote:
Sat Aug 20, 2022 6:36 am
...
Check sample here - https://www.renpy.org/doc/html/screens. ... -statement

recreation
Regular
Posts: 42
Joined: Sun Jul 01, 2018 8:32 am
Contact:

Re: "add" with dissolve

#3 Post by recreation » Sat Aug 20, 2022 8:47 am

Alex wrote:
Sat Aug 20, 2022 7:39 am
recreation wrote:
Sat Aug 20, 2022 6:36 am
...
Check sample here - https://www.renpy.org/doc/html/screens. ... -statement
Oh wow, I didn't know that one, thanks!
Though now I realized another problem...
When I change the image via the two buttons the transition works, but not when I change the variables in the scene (pov1 and pov2). I guess that's because technically the image is already shown and no screen action is triggered. The image changes as soon as the variable changes, but again without transition :/
Any idea?

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: "add" with dissolve

#4 Post by Alex » Sat Aug 20, 2022 10:24 am

recreation wrote:
Sat Aug 20, 2022 8:47 am
...
Any idea?
Well, try to change your variable using screen action... outside the screen.

Like

Code: Select all

label some_label:
    "blah-blah-blah"
    $ SetScreenVariable("n", 3)()
    "?!"
(screen actions are functions, so you can use them as a single line python code or inside a python block; just don't forget the pair of extra parentheses at the end)

recreation
Regular
Posts: 42
Joined: Sun Jul 01, 2018 8:32 am
Contact:

Re: "add" with dissolve

#5 Post by recreation » Sat Aug 20, 2022 1:49 pm

Alex wrote:
Sat Aug 20, 2022 10:24 am
recreation wrote:
Sat Aug 20, 2022 8:47 am
...
Any idea?
Well, try to change your variable using screen action... outside the screen.

Like

Code: Select all

label some_label:
    "blah-blah-blah"
    $ SetScreenVariable("n", 3)()
    "?!"
(screen actions are functions, so you can use them as a single line python code or inside a python block; just don't forget the pair of extra parentheses at the end)
That does nothing sadly, doesn't even throw an error, the script just goes on without swapping the image :/

Edit: SetLocalVariable works, but it also doesn't use a transition.

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: "add" with dissolve

#6 Post by Alex » Sat Aug 20, 2022 3:39 pm

recreation wrote:
Sat Aug 20, 2022 1:49 pm
...
That does nothing sadly, doesn't even throw an error, the script just goes on without swapping the image :/

Edit: SetLocalVariable works, but it also doesn't use a transition.
What's the actual code you've used?

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

Re: "add" with dissolve

#7 Post by Ocelot » Sun Aug 21, 2022 12:37 pm

Try to throw restart_interaction in there:

Code: Select all

label change:
    python:
        campov = True
        renpy.restart_interaction()
< < insert Rick Cook quote here > >

recreation
Regular
Posts: 42
Joined: Sun Jul 01, 2018 8:32 am
Contact:

Re: "add" with dissolve

#8 Post by recreation » Mon Aug 22, 2022 3:04 am

Alex wrote:
Sat Aug 20, 2022 3:39 pm
recreation wrote:
Sat Aug 20, 2022 1:49 pm
...
That does nothing sadly, doesn't even throw an error, the script just goes on without swapping the image :/

Edit: SetLocalVariable works, but it also doesn't use a transition.
What's the actual code you've used?

Code: Select all

label something:

	...
	
        $ campov = True
        $ pov1 = "d7pf11" # first movie pov
        $ pov2 = "d7pf12" # first movie 3rd person
        $ povstart = True
        show screen povscreen() with dissolve
        "some dialogue"
        "more dialogue"
        ...
        $ pov1 = "d7pf21" # second movie pov
        $ pov2 = "d7pf22" # second movie 3rd person
        
        ...
        
screen povscreen():
    if povstart:
        add "switch_cam1_idle.png" yalign .01 xalign .99 at btnZoomSwitch
        $ store.povstart = False
    showif campov:
        add pov1 at swap_dissolve
        imagebutton auto "switch_cam1_%s.png" action [ ToggleVariable("campov", true_value=True,false_value=False)] yalign .01 xalign .99 at btnzoom
    else:
        add pov2 at swap_dissolve
        imagebutton auto "switch_cam2_%s.png" action [ ToggleVariable("campov", true_value=True,false_value=False)] yalign .01 xalign .99 at btnzoom
transform swap_dissolve:
    on appear:
        alpha 1.0
    on show:
        linear .5 alpha 1.0
    on hide:
        linear .5 alpha 0.0
        
Ocelot wrote:
Sun Aug 21, 2022 12:37 pm
Try to throw restart_interaction in there:

Code: Select all

label change:
    python:
        campov = True
        renpy.restart_interaction()
I tried that already after the "pov" variables change (and also inside the screen itself), but that also doesn't trigger the transition.

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: "add" with dissolve

#9 Post by Alex » Mon Aug 22, 2022 2:45 pm

recreation wrote:
Mon Aug 22, 2022 3:04 am
...
You almost did it. Images will replace each other with transform if you'll change the value of variable that is checked by 'showif'.
Your code with minor changes:

Code: Select all

# images, movies, etc.
image d7pf11:
    Solid("#c00")
    size(100, 100)
    
image d7pf12:
    Solid("#00c")
    size(100, 100)
    
image d7pf21:
    Solid("#c00")
    size(200, 200)
    
image d7pf22:
    Solid("#00c")
    size(200, 200)

label start:
    "..."
    
    $ campov = 999 # some value to fail the 'showif' check 
    $ pov1 = "d7pf11" # first movie pov
    $ pov2 = "d7pf12" # first movie 3rd person
    $ povstart = True
    show screen povscreen with dissolve
    "some dialogue"
    $ campov = 0 # show pov
    "...dialogue..."
    $ campov = 1 # show 3rd person  view
    "more dialogue"
    
    $ pov1 = "d7pf21" # second movie pov
    $ campov = 0
    "..."
    $ pov2 = "d7pf22" # second movie 3rd person
    $ campov = 1
    "... ..."
    $ campov = 0
    "..."
    $ campov = 999 # hide movies
    
    "?!"
    
    
        
screen povscreen():
    #if povstart:
    #    add "switch_cam1_idle.png" yalign .01 xalign .99 at btnZoomSwitch
    #    $ store.povstart = False
    showif campov == 0: # pov
        add pov1 at swap_dissolve
        #imagebutton auto "switch_cam1_%s.png" action [ ToggleVariable("campov", true_value=True,false_value=False)] yalign .01 xalign .99 at btnzoom
    showif campov == 1: # 3rd person
        add pov2 at swap_dissolve
        #imagebutton auto "switch_cam2_%s.png" action [ ToggleVariable("campov", true_value=True,false_value=False)] yalign .01 xalign .99 at btnzoom


transform swap_dissolve:
    on appear:
        alpha 1.0
    on show:
        alpha 0.0 # some value to start from
        linear 2.5 alpha 1.0
    on hide:
        linear 2.5 alpha 0.0

recreation
Regular
Posts: 42
Joined: Sun Jul 01, 2018 8:32 am
Contact:

Re: "add" with dissolve

#10 Post by recreation » Mon Aug 22, 2022 8:39 pm

Alex wrote:
Mon Aug 22, 2022 2:45 pm
recreation wrote:
Mon Aug 22, 2022 3:04 am
...
You almost did it. Images will replace each other with transform if you'll change the value of variable that is checked by 'showif'.
Sorry if I didn't make it clear enough, but I think you misunderstood my intentions.
The scene is supposed to work like every other normal vn scene, the only difference is that you can swap the view with a button. That view is supposed to stay the same until either the scene is over, or the player hits the button again. So changing the variable for the view inside the script is against it's purpose.
One way to make it work is to "show" the screen with dissolve everytime the images (/movies) change, but I'd like to avoid that.
I thought that since the images change by just changing the variables, and without showing the screen again and again, there must be a way to make them use a transform.

User avatar
Alex
Lemma-Class Veteran
Posts: 2981
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: "add" with dissolve

#11 Post by Alex » Tue Aug 23, 2022 2:22 pm

recreation wrote:
Mon Aug 22, 2022 8:39 pm
...That view is supposed to stay the same until either the scene is over, or the player hits the button again. So changing the variable for the view inside the script is against it's purpose.
...
I thought that since the images change by just changing the variables, and without showing the screen again and again, there must be a way to make them use a transform.
If you'll simply change the value of variable that stores the image then image will change definitely, but there will be no reason for transform to do anything, 'cause technically this is the same image onscreen (the variable is the same).

The 'showif' condition makes the screen show different images (stored in different variables), so transforms are working.

And you can change values for 'campov' variable using buttons (I've commented them 'cause I didn't have proper images for them).

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot]