How to remove / replace added image

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
Luxliev
Veteran
Posts: 242
Joined: Sat Feb 07, 2015 11:01 am
Soundcloud: Luxliev
Contact:

How to remove / replace added image

#1 Post by Luxliev »

How do I replace or remove image that I've added by using "add" command? Code example below:

Code: Select all

init python:
    add_button_active = 0
    remove_button_active = 0

screen add_remove:
    vbox:
        textbutton "Add": 
            action SetVariable('add_button_active', 1)
        
        textbutton "Remove": 
            action SetVariable('remove_button_active', 1)
    
    if add_button_active:
        add "none.png" xalign 0.25
    
    #if remove_button_active:                               ???
        #remove "none.png" xalign 0.25                      ???

label start:
    show screen add_remove

    "Hello, world."

    return
Newest classical cover: Advance Wars - Sami Theme: https://www.youtube.com/watch?v=657Jt7hJRVc

Forum with my music: http://luxliev.proboards.com/

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: How to remove / replace added image

#2 Post by Remix »

Easiest to just use one variable...
As the screen is redrawn every interaction, the 'if show_button:' is evaluated every click...

Code: Select all

default show_button = False

screen add_remove:
    vbox:
        textbutton "Add": 
            action SetVariable('show_button', True) sensitive not show_button
        textbutton "Remove": 
            action SetVariable('show_button', False) sensitive show_button
        textbutton "Toggle": 
            action ToggleVariable('show_button') 
    
    if show_button:
        add "none.png" xalign 0.25
    

label start:
    show screen add_remove

    "Hello, world."
Frameworks & Scriptlets:

User avatar
Luxliev
Veteran
Posts: 242
Joined: Sat Feb 07, 2015 11:01 am
Soundcloud: Luxliev
Contact:

Re: How to remove / replace added image

#3 Post by Luxliev »

You can do it this way but this is not why I want to remove image. I want to remove/replace image because it's sprite animation. Because of that I need to remove other image. Otherwise two animations will overlap with one another.

Thanks for answer. I didn't know about ToggleVariable this will be useful in another part of my code.
Newest classical cover: Advance Wars - Sami Theme: https://www.youtube.com/watch?v=657Jt7hJRVc

Forum with my music: http://luxliev.proboards.com/

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]