Actions on hovering - why won't my code work?

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
lykoia
Newbie
Posts: 22
Joined: Tue Apr 14, 2020 11:15 am
Contact:

Actions on hovering - why won't my code work?

#1 Post by lykoia »

Hey all, newbie here,

I wanted to change a variable on hover but unfortunately it doesn't work.
Here's the code:

Code: Select all

imagebutton:
        focus_mask True
        idle "1stfloor-button-idle"
        hover "1stfloor-button-hover"
        hovered SetVariable("schoolfloor", "0")
        xalign 1.0
        action NullAction()
Why won't it work?

Thanks in advance.

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Actions on hovering - why won't my code work?

#2 Post by rayminator »

it because you have nothing in the action renpy is reading your code right by ignoring that button cause you have nullaction

hovered SetVariable("schoolfloor", "0") won't do anything not in less it has something in the action try putting setvariable in action

lykoia
Newbie
Posts: 22
Joined: Tue Apr 14, 2020 11:15 am
Contact:

Re: Actions on hovering - why won't my code work?

#3 Post by lykoia »

rayminator wrote: Sat Jan 02, 2021 10:06 am it because you have nothing in the action renpy is reading your code right by ignoring that button cause you have nullaction

hovered SetVariable("schoolfloor", "0") won't do anything not in less it has something in the action try putting setvariable in action
I changed it so it's now:
imagebutton:
focus_mask True
idle "1stfloor-button-idle"
hover "1stfloor-button-hover"
hovered SetVariable("schoolfloor", "0")
xalign 1.0
action SetVariable("schoolfloor", "0")
And it still doesn't work.
Did I do something wrong?

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Actions on hovering - why won't my code work?

#4 Post by rayminator »

are you using define or default

Code: Select all

define schoolfloor = 0 (doesn't change)
default schoolfloor = 0 (changes)

action SetVariable("schoolfloor", 1)

lykoia
Newbie
Posts: 22
Joined: Tue Apr 14, 2020 11:15 am
Contact:

Re: Actions on hovering - why won't my code work?

#5 Post by lykoia »

rayminator wrote: Sat Jan 02, 2021 10:44 am are you using define or default

Code: Select all

define schoolfloor = 0 (doesn't change)
default schoolfloor = 0 (changes)

action SetVariable("schoolfloor", 1)
I'm using default

rayminator
Miko-Class Veteran
Posts: 793
Joined: Fri Feb 09, 2018 12:05 am
Location: Canada
Contact:

Re: Actions on hovering - why won't my code work?

#6 Post by rayminator »

lykoia wrote: Sat Jan 02, 2021 10:46 am
rayminator wrote: Sat Jan 02, 2021 10:44 am are you using define or default

Code: Select all

define schoolfloor = 0 (doesn't change)
default schoolfloor = 0 (changes)

action SetVariable("schoolfloor", 1)
I'm using default
ok I did notice the you are putting "" around the number hovered SetVariable("schoolfloor", "0") when it should be hovered SetVariable("schoolfloor", 0)

lykoia
Newbie
Posts: 22
Joined: Tue Apr 14, 2020 11:15 am
Contact:

Re: Actions on hovering - why won't my code work?

#7 Post by lykoia »

rayminator wrote: Sat Jan 02, 2021 10:52 am ok I did notice the you are putting "" around the number hovered SetVariable("schoolfloor", "0") when it should be hovered SetVariable("schoolfloor", 0)
I changed it but nothing changed.

Here's the entire code:

Code: Select all

screen mapweek00():
    default schoolfloor = 0
    imagebutton:
        if schoolfloor == 0:
            idle "school-map-00"
        elif schoolfloor == 1:
            idle "school-map-01"
        elif schoolfloor == 2:
            idle "school-map-02"
        xalign 0.5
        yalign 0.5
        action NullAction()
    imagebutton:
        idle "1stfloor-button-idle"
        hover "1stfloor-button-hover"
        hovered SetVariable("schoolfloor", 0)
        xalign 1.0
        action SetVariable("schoolfloor", 0)
       imagebutton:
        focus_mask True
        idle "2ndfloor-button-idle"
        hover "2ndfloor-button-hover"
        hovered SetVariable("schoolfloor", 1)
        xalign 1.0
        yalign 0.5
        action SetVariable("schoolfloor", 1)
    imagebutton:
        focus_mask True
        idle "3rdfloor-button-idle"
        hover "3rdfloor-button-hover"
        hovered SetVariable("schoolfloor", 2)
        xalign 1.0
        action SetVariable("schoolfloor", 2)
Maybe I did something wrong here?

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: Actions on hovering - why won't my code work?

#8 Post by Remix »

Use SetLocalVariable or SetScreenVariable

Your actions/hovered (btw hovered will work with a NullAction on the action) are not altering the screen variable, just a global variable.
In most cases it makes more sense to just use global variables though (easier to keep track of)

Code: Select all

default var = 0 # GLOBAL

screen update_var():
    default svar = 10 # SCREEN
    vbox:
        text "Global: [var!q]"
        text "Screen: [svar!q]"
        textbutton "Add":
            hovered [
                # Increment GLOBAL variable
                SetVariable("var", var+1),
                # Decrement SCREEN variable
                SetScreenVariable("svar", svar-1) ]
            action NullAction()

label start:

    show screen update_var

    pause
Frameworks & Scriptlets:

lykoia
Newbie
Posts: 22
Joined: Tue Apr 14, 2020 11:15 am
Contact:

Re: Actions on hovering - why won't my code work?

#9 Post by lykoia »

Remix wrote: Sat Jan 02, 2021 11:20 am Use SetLocalVariable or SetScreenVariable

Your actions/hovered (btw hovered will work with a NullAction on the action) are not altering the screen variable, just a global variable.
In most cases it makes more sense to just use global variables though (easier to keep track of)

Code: Select all

default var = 0 # GLOBAL

screen update_var():
    default svar = 10 # SCREEN
    vbox:
        text "Global: [var!q]"
        text "Screen: [svar!q]"
        textbutton "Add":
            hovered [
                # Increment GLOBAL variable
                SetVariable("var", var+1),
                # Decrement SCREEN variable
                SetScreenVariable("svar", svar-1) ]
            action NullAction()
label start:

    show screen update_var

    pause
It works! I've been looking for a solution for this problem for so long! Thank you so much!

Post Reply

Who is online

Users browsing this forum: henne, Ocelot