Button that change background many times

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
BadRos
Regular
Posts: 39
Joined: Fri Dec 28, 2018 11:19 am
Location: Italy
Contact:

Button that change background many times

#1 Post by BadRos »

Im confused, im trying to make a button that can change the background (or maybe in the future other things) and im trying to read things online about it but im in the wrong road, im not understanding how to use the buttons for actions, i need a button that change the background like 5 times, like "press one time = bg1, second time = bg3 ecc.." and that after the fifth bg it returns to the main label like if you didn't click it, but i also need that this can work in different labels, like "label 1 press one = bg10. label 2 press one = bg20" but with the button in the same position and with the same image, i hope i didn't confuse everyone there like me lol, what im doing wrong? probably everything. Thanks to everyone

Code: Select all

screen changeviewarmorbutton:
    vbox xalign 1.0 yalign 0:
        imagebutton:
            idle "changeviewbuttonarmor.png"
            hover "changeviewbuttonarmor.png"
            action ui.callsinnewcontext ("togglechangeviewbuttonarmor")

Code: Select all

                
                $renpy.pause()
                $ u = "user"
                x "X [u]"
                imagebutton:
                    jump changeviewbutton
                jump onetwothree
label changeviewbuttonarmor:
    imagebutton:
        idle "changeviewbuttonarmor.png"
        hover "changeviewbuttonarmor.png"
        action (show posebasestand1, show posebasestand2, show posebasestand3, show posebasestand4, show posebasestand5,)

BadRos
Regular
Posts: 39
Joined: Fri Dec 28, 2018 11:19 am
Location: Italy
Contact:

Re: Button that change background many times

#2 Post by BadRos »

Ouch the error is "I'm sorry, but errors were detected in your script. Please correct theerrors listed below, and try again.
File "game/sbmode.rpy", line 92: expected statement.
imagebutton:
File "game/sbmode.rpy", line 96: expected statement.
imagebutton:
Ren'Py Version: Ren'Py 7.1.3.1092
Mon Jan 14 17:36:04 2019
"

BadRos
Regular
Posts: 39
Joined: Fri Dec 28, 2018 11:19 am
Location: Italy
Contact:

Re: Button that change background many times

#3 Post by BadRos »

im doing some changes and i have the output of the image but it doesn't switch with the others images

Code: Select all

screen buttone():
     textbutton "ChangeView" xalign 0 yalign 25 action Jump("posebasestand")

Code: Select all

label posebasestand:
    $ posebasestand = 0
    if posebasestand == 0:
        show posebasestandone
        $ posebasestand = 1
        jump normal
    elif posebasestand == 1:
        show posebasestandtwo
        $ posebasestand = 2
        jump normal
    elif posebasestand == 2:
        show posebasestandthree
        $ posebasestand = 3
        jump normal
    elif posebasestand == 3:
        show posebasestandfour
        $ posebasestand = 4
        jump normal
    elif posebasestand == 4:
        show posebasestandfive
        $ posebasestand = 5
        jump normal
    elif posebasestand == 5:
        show posebasestandone
        $ posebasestand = 1
        jump normal
    else:
        "else"
        jump normal
This is the change

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

Re: Button that change background many times

#4 Post by Alex »

Yes, this won't switch because of

Code: Select all

label posebasestand:
    $ posebasestand = 0
Everytime you send player to this label, the posebasestand variable is set to 0.

Anyway, try dynamc images instead - https://www.renpy.org/doc/html/changelo ... mic-images
viewtopic.php?f=8&t=49683&p=484534#p484630

If you have posebasestand0.png, posebasestand1.png, posebasestand2.png, posebasestand3.png, posebasestand4.png and posebasestand5.png try

Code: Select all

image posebasestand = "posebasestand[my_var].png"
default my_var = 0

screen buttone():
     textbutton "ChangeView" xalign 0 yalign 25 action If(my_var>4, true=SetVariable("my_var", 0), false=SetVariable("my_var", my_var+1))

label start:
    scene posebasestand
    show screen buttone
    "Try to click..."
    "?"

BadRos
Regular
Posts: 39
Joined: Fri Dec 28, 2018 11:19 am
Location: Italy
Contact:

Re: Button that change background many times

#5 Post by BadRos »

Code: Select all

label posebasestand:
    $ posebasestand = 0
I need to pay more attention about what i write...

So i tried the code you gave me, it work's really well, i will search some more about it and i will try to understand it. Thanks, this is the second time you help me, i owe you, thanks again

BadRos
Regular
Posts: 39
Joined: Fri Dec 28, 2018 11:19 am
Location: Italy
Contact:

Re: Button that change background many times

#6 Post by BadRos »

Also another question, it's possible to use the same code you show me with an imagebutton? Have a good day

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

Re: Button that change background many times

#7 Post by Alex »

Yes, it doesn't matter - choose what suits you better textbutton, imagebutton, button or imagemap - https://www.renpy.org/doc/html/screens.html

Post Reply

Who is online

Users browsing this forum: No registered users