Making a movie background play when a image button is hovered

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
YumaDazai
Regular
Posts: 35
Joined: Wed Jul 04, 2018 4:10 pm
Projects: PD9
Contact:

Making a movie background play when a image button is hovered

#1 Post by YumaDazai »

So as the title says, I'm not sure how to get the movie to play. I can get it to play if the button is clicked, but I can not get it to play when the button is hovered on.
The code for the button is as follows

Code: Select all

define selection_number = 0
define selection_hovered = 0
define output = 0


screen menu_button:
    imagebutton:
        idle "/images/Wheel UI/menu_button.jpg" action Show("wheel_UI"), Show("stuff_wheel_displays_or_does"), Hide("menu_button") focus_mask True

screen stuff_wheel_displays_or_does:

    if output == 1:
        add "/images/Wallpapers/w (1).jpg"
    elif output == 2:
        add "/images/Wallpapers/w (2).jpg"
    elif output == 3:
        add "/images/Wallpapers/w (3).jpg"
    elif output == 4:
        add "/images/Wallpapers/w (4).jpg"
    elif output == 5:
        add "/images/Wallpapers/w (5).jpg"
    elif output == 6:
        add "/images/Wallpapers/w (6).jpg"
    elif output == 7:
        add "/images/Wallpapers/w (7).jpg"
    elif output == 8:
        add "/images/Wallpapers/w (8).jpg"


screen wheel_UI:

    add "/images/Wheel UI/Wheel.png"
    if selection_number == 1 or selection_number == 2 or selection_number == 3 or selection_number == 4 or selection_number == 5 or selection_number == 6 or selection_number == 7 or selection_number == 8:
        imagebutton:
            idle "/images/Wheel UI/expanded_button.png" action SetVariable("output", selection_number), Hide("wheel_UI"), Show("menu_button"), SetVariable("selection_number", 0) focus_mask True
    else:
        add "/images/Wheel UI/minimized_button.png"

    imagebutton:
        idle "/images/Wheel UI/Acurate_hover_1.png" action SetVariable("selection_number", 1) hovered SetVariable("selection_hovered", 1) unhovered SetVariable("selection_hovered", 0) focus_mask True
    imagebutton:
        idle "/images/Wheel UI/Acurate_hover_2.png" action SetVariable("selection_number", 2) hovered SetVariable("selection_hovered", 2) unhovered SetVariable("selection_hovered", 0) focus_mask True
    imagebutton:
        idle "/images/Wheel UI/Acurate_hover_3.png" action SetVariable("selection_number", 3) hovered SetVariable("selection_hovered", 3) unhovered SetVariable("selection_hovered", 0) focus_mask True
    imagebutton:
        idle "/images/Wheel UI/Acurate_hover_4.png" action SetVariable("selection_number", 4) hovered SetVariable("selection_hovered", 4) unhovered SetVariable("selection_hovered", 0) focus_mask True
    imagebutton:
        idle "/images/Wheel UI/Acurate_hover_5.png" action SetVariable("selection_number", 5) hovered SetVariable("selection_hovered", 5) unhovered SetVariable("selection_hovered", 0) focus_mask True
    imagebutton:
        idle "/images/Wheel UI/Acurate_hover_6.png" action SetVariable("selection_number", 6) hovered SetVariable("selection_hovered", 6) unhovered SetVariable("selection_hovered", 0) focus_mask True
    imagebutton:
        idle "/images/Wheel UI/Acurate_hover_7.png" action [SetVariable("selection_number", 7)] hovered SetVariable[("selection_hovered", 7), Jump("test_movie")] unhovered SetVariable("selection_hovered", 0) focus_mask True
    imagebutton:
        idle "/images/Wheel UI/Acurate_hover_8.png" action SetVariable("selection_number", 8) hovered SetVariable("selection_hovered", 8) unhovered SetVariable("selection_hovered", 0) focus_mask True


    if selection_hovered == 1 or selection_number == 1:
        add "/images/Wheel UI/Wheel_selection_1.png"
    if selection_hovered == 2 or selection_number == 2:
        add "/images/Wheel UI/Wheel_selection_2.png"
    if selection_hovered == 3 or selection_number == 3:
        add "/images/Wheel UI/Wheel_selection_3.png"
    if selection_hovered == 4 or selection_number == 4:
        add "/images/Wheel UI/Wheel_selection_4.png"
    if selection_hovered == 5 or selection_number == 5:
        add "/images/Wheel UI/Wheel_selection_5.png"
    if selection_hovered == 6 or selection_number == 6:
        add "/images/Wheel UI/Wheel_selection_6.png"
    if selection_hovered == 7 or selection_number == 7:
        add "/images/Wheel UI/Wheel_selection_7.png"
    if selection_hovered == 8 or selection_number == 8:
        add "/images/Wheel UI/Wheel_selection_8.png"
I am focusing on button 7 as the test button for playing the movie background.
The way I got to get the movie to play when clcked was using the Jump fuction in the action section. I thought I could do the same with the hover fuction, but I run into this error

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 8, in script
    $ result = ui.interact() #freezes the textbox if used with text
  File "game/script.rpy", line 8, in <module>
    $ result = ui.interact() #freezes the textbox if used with text
  File "game/wheel ui screens.rpy", line 30, in execute
    screen wheel_UI:
  File "game/wheel ui screens.rpy", line 30, in execute
    screen wheel_UI:
  File "game/wheel ui screens.rpy", line 51, in execute
    imagebutton:
  File "game/wheel ui screens.rpy", line 51, in keywords
    imagebutton:
  File "game/wheel ui screens.rpy", line 52, in <module>
    idle "/images/Wheel UI/Acurate_hover_7.png" action [SetVariable("selection_number", 7)] hovered SetVariable[("selection_hovered", 7), Jump("test_movie")] unhovered SetVariable("selection_hovered", 0) focus_mask True
TypeError: 'function' object has no attribute '__getitem__'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/script.rpy", line 8, in script
    $ result = ui.interact() #freezes the textbox if used with text
  File "renpy/ast.py", line 928, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "renpy/python.py", line 2245, in py_exec_bytecode
    exec(bytecode, globals, locals)
  File "game/script.rpy", line 8, in <module>
    $ result = ui.interact() #freezes the textbox if used with text
  File "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 3315, in interact
    repeat, rv = self.interact_core(preloads=preloads, trans_pause=trans_pause, pause=pause, pause_start=pause_start, **kwargs)
  File "renpy/display/core.py", line 3735, in interact_core
    root_widget.visit_all(lambda i : i.per_interact())
  File "renpy/display/core.py", line 568, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 568, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/core.py", line 568, in visit_all
    d.visit_all(callback, seen)
  File "renpy/display/screen.py", line 436, in visit_all
    callback(self)
  File "renpy/display/core.py", line 3735, in <lambda>
    root_widget.visit_all(lambda i : i.per_interact())
  File "renpy/display/screen.py", line 447, in per_interact
    self.update()
  File "renpy/display/screen.py", line 637, in update
    self.screen.function(**self.scope)
  File "game/wheel ui screens.rpy", line 30, in execute
    screen wheel_UI:
  File "game/wheel ui screens.rpy", line 30, in execute
    screen wheel_UI:
  File "game/wheel ui screens.rpy", line 51, in execute
    imagebutton:
  File "game/wheel ui screens.rpy", line 51, in keywords
    imagebutton:
  File "game/wheel ui screens.rpy", line 52, in <module>
    idle "/images/Wheel UI/Acurate_hover_7.png" action [SetVariable("selection_number", 7)] hovered SetVariable[("selection_hovered", 7), Jump("test_movie")] unhovered SetVariable("selection_hovered", 0) focus_mask True
TypeError: 'function' object has no attribute '__getitem__'

Windows-10-10.0.19041
Ren'Py 7.4.10.2178
Greybox 1.0
Thu May 12 21:48:08 2022
I'm not sure how to fix the issue. Any help would be great!
Thanks!
Programmer that will work paid and or for free! Message me on discord for more info at: Yuma#8158

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

Re: Making a movie background play when a image button is hovered

#2 Post by rayminator »

you properly can use Mousearea for this (it might work or it might not work)
https://www.renpy.org/doc/html/screens. ... -mousearea

for the error that you gotten you have this [ in the wrong spot

Code: Select all

hovered SetVariable[("selection_hovered", 7), Jump("test_movie")] 

User avatar
YumaDazai
Regular
Posts: 35
Joined: Wed Jul 04, 2018 4:10 pm
Projects: PD9
Contact:

Re: Making a movie background play when a image button is hovered

#3 Post by YumaDazai »

rayminator wrote: Thu May 12, 2022 11:02 pm for the error that you gotten you have this [ in the wrong spot

Code: Select all

hovered SetVariable[("selection_hovered", 7), Jump("test_movie")] 
Yeah, That didn't fix it unfortunately. I still get the same error.

For the mousearea, it didnt help either. At this point I'm not sure if there is a fix for this.
Programmer that will work paid and or for free! Message me on discord for more info at: Yuma#8158

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

Re: Making a movie background play when a image button is hovered

#4 Post by Alex »

YumaDazai wrote: Sat May 14, 2022 8:46 pm ...
When you hovering button the 'hovered' action will run again and again, so jump action is not good here.
Why don't you show the movie as part of the screen - the way you show images?

Code: Select all

    if selection_hovered == 1 or selection_number == 1:
        add "/images/Wheel UI/Wheel_selection_1.png"
    if selection_hovered == 2 or selection_number == 2:
        add "/images/Wheel UI/Wheel_selection_2.png"

User avatar
YumaDazai
Regular
Posts: 35
Joined: Wed Jul 04, 2018 4:10 pm
Projects: PD9
Contact:

Re: Making a movie background play when a image button is hovered

#5 Post by YumaDazai »

Alex wrote: Sun May 15, 2022 6:09 am
YumaDazai wrote: Sat May 14, 2022 8:46 pm ...
When you hovering button the 'hovered' action will run again and again, so jump action is not good here.
Why don't you show the movie as part of the screen - the way you show images?

Code: Select all

    if selection_hovered == 1 or selection_number == 1:
        add "/images/Wheel UI/Wheel_selection_1.png"
    if selection_hovered == 2 or selection_number == 2:
        add "/images/Wheel UI/Wheel_selection_2.png"
By replacing the add function with the play function, it gives the error

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/wheel ui screens.rpy", line 70: u'play' is not a keyword argument or valid child for the screen statement.
    play movie "test.ogv"
        ^

Ren'Py Version: Ren'Py 7.4.10.2178
Mon May 16 17:32:15 2022
If I just use the add function, it wont work because .ogv is not a supported image, as it is a video file.
Programmer that will work paid and or for free! Message me on discord for more info at: Yuma#8158

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

Re: Making a movie background play when a image button is hovered

#6 Post by Alex »

YumaDazai wrote: Mon May 16, 2022 5:33 pm ...
If I just use the add function, it wont work because .ogv is not a supported image, as it is a video file.
Just create an image out of video and add it to the screen (see the sample with video bg for main menu) - https://www.renpy.org/doc/html/movie.ht ... ie-sprites

User avatar
YumaDazai
Regular
Posts: 35
Joined: Wed Jul 04, 2018 4:10 pm
Projects: PD9
Contact:

Re: Making a movie background play when a image button is hovered

#7 Post by YumaDazai »

Alex wrote: Tue May 17, 2022 11:56 am
YumaDazai wrote: Mon May 16, 2022 5:33 pm ...
If I just use the add function, it wont work because .ogv is not a supported image, as it is a video file.
Just create an image out of video and add it to the screen (see the sample with video bg for main menu) - https://www.renpy.org/doc/html/movie.ht ... ie-sprites
That worked wonderfully, thanks! Just a quick side question. Does renpy support playing videos with transparency, or can you play the video while keeping the ui on top of it, because I can get the video to play, but it covers the wheel ui, so you can't see it. I tried adding a video with a transparent space, but it just shows black
Programmer that will work paid and or for free! Message me on discord for more info at: Yuma#8158

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

Re: Making a movie background play when a image button is hovered

#8 Post by Alex »

Things in screens are shown onscreen in order they coded in your script. So just chang the order of elements - add background movie and than show wheel ui.

Also, check the movie sprite documentation (the same link).

User avatar
YumaDazai
Regular
Posts: 35
Joined: Wed Jul 04, 2018 4:10 pm
Projects: PD9
Contact:

Re: Making a movie background play when a image button is hovered

#9 Post by YumaDazai »

Alex wrote: Tue May 17, 2022 4:32 pm Things in screens are shown onscreen in order they coded in your script. So just chang the order of elements - add background movie and than show wheel ui.

Also, check the movie sprite documentation (the same link).
Yep. That worked! I also added a mask to see if the would help, and it did, but it has a issue where it flashes the mask on and off, I'm not sure why it's doing that lol
Programmer that will work paid and or for free! Message me on discord for more info at: Yuma#8158

User avatar
YumaDazai
Regular
Posts: 35
Joined: Wed Jul 04, 2018 4:10 pm
Projects: PD9
Contact:

Re: Making a movie background play when a image button is hovered

#10 Post by YumaDazai »

nevermind, Figured it out. I just switched the files from .ogv to .webm, and it fixed itself. Thanks for the help!
Programmer that will work paid and or for free! Message me on discord for more info at: Yuma#8158

Post Reply

Who is online

Users browsing this forum: No registered users