[Solved] Updating screen background on button hover

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
Keul
Regular
Posts: 49
Joined: Wed May 06, 2009 3:42 am
Location: France - Strasbourg
Contact:

[Solved] Updating screen background on button hover

#1 Post by Keul » Sat Oct 26, 2013 8:02 pm

I'd like to update the background of a screen when a button is hovered.

the hovered property can trigger an action when the button is hovered/unhovered. But I don't know how to change the background of a screen with an action

I've tried this way but it doesn't work.

Code: Select all

screen chapter_select:
    if testbgcs = 0:
        add "images/interface/images/interface/base.png"
    if testbgcs = 1:
        add "images/interface/images/interface/opt1.png"
    imagebutton auto "images/interface/main_menu/start_%s.png" action Return(value=1) hovered SetScreenVariable("testbgcs", 1) unhovered SetScreenVariable("testbgcs", 0)
    
label test:
    scene test1 
    "test1"
    call screen chapter_select
thank you for helping
Last edited by Keul on Sun Oct 27, 2013 6:24 am, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Updating screen background on button hover

#2 Post by PyTom » Sat Oct 26, 2013 11:54 pm

That's a syntax error, but replacing = with == in both places should yield working code.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
Keul
Regular
Posts: 49
Joined: Wed May 06, 2009 3:42 am
Location: France - Strasbourg
Contact:

Re: Updating screen background on button hover

#3 Post by Keul » Sun Oct 27, 2013 6:24 am

Code is working now ... I've made PyTom lose time because of stupid things ...

I was hesitating if the comparator operator was "=" or "==" because I was using some shitty language that use = for comparison last days T_T.

Should spend more time on debug before posting in the forum...

Working code for those interested:

Code: Select all

init -2:
    $testbgcs = 0 #you can remove $ sign if in python block

screen chapter_select:
    if testbgcs == 0:
        add "images/interface/base.png"
    if testbgcs == 1:
        add "images/interface/opt1.png"
    imagebutton auto "images/interface/main_menu/start_%s.png" action Return(value=1) hovered SetScreenVariable("testbgcs", 1) unhovered SetScreenVariable("testbgcs", 0)
   
label test:
    scene test1
    "test1"
    call screen chapter_select

Post Reply

Who is online

Users browsing this forum: Ocelot