Ren'Py Is there a way to add an image to renpy.notify?

Izakiya

Member
Apr 29, 2023
153
584
147
I just want to add a small image to the end of the renpy notification. Like a thumbs up when you make the right choice or something. I have this added to my screens.rpy but it's not working. It's showing the default notify message.


screen notify(message):
frame:
style "notify_frame"
at notify_fade
padding (8, 5)
hbox:
spacing 10
add "images/thumb.png" xysize (32, 32)
text message style "notify_text"

transform notify_fade:
on show:
alpha 0.0
linear 0.2 alpha 1.0
pause 2.5
linear 0.5 alpha 0.0
on hide:
alpha 0.0

style notify_frame is default:
xalign 0.98
yalign 0.95
background "#111C"
padding (10, 5)
xmaximum 450
yminimum 40

style notify_text is default:
color "#FFD700"
font "fonts/wingdings.ttf"
size 20
outlines [(1, "#000", 0, 0)]
yalign 0.5
 

79flavors

Well-Known Member
Respected User
Jun 14, 2018
1,663
2,355
462
Keep in mind that screen notify(message): is just a RenPy .

If it were me, I'd copy the existing screen as a brand new screen and alter that new screen to suit my needs.
That way, the existing notify remains unchanged and can be used as normal, but the new version can be used along side it.

Beyond that, it's only a case of replicating what RenPy does.

The manual for explains that $renpy.notify(): just executes the name of the function stored in .

When you look behind the scenes, you find this code (in exports.py:

Python:
def notify(message):

    renpy.config.notify(message)


def display_notify(message):

    hide_screen('notify')
    show_screen('notify', message=message)
    restart_interaction()

The value of config.notify is display_notify.
Armed with that knowledge, I coded a test script that looked like this:

Python:
init python:
    def display_notify_with_image(displayable, message):
        renpy.hide_screen('notify')
        renpy.show_screen('notify_with_image', displayable=displayable, message=message)
        renpy.restart_interaction()

screen notify_with_image(displayable, message):

    tag notify
    zorder 100
    style_prefix "notify"

    frame at notify_appear:
        hbox spacing 10:
            add displayable
            text "[message!tq]"

    timer 3.25 action Hide('notify')

label start:

    scene black with fade
    "*** START ***"

    $ display_notify_with_image('thumbs_up', "Test notification")
    centered "This my first test"

    $ renpy.notify("test message #2")
    $ display_notify_with_image('thumbs_up', "Test image #2")

    centered "Just waiting..."

    $ display_notify_with_image('thumbs_up', "Test image #3")
    $ renpy.notify("test message #3")

    centered "Still waiting..."

    "*** THE END ***"

    return

This code assumes a displayable exists called thumbs_up, which implies a images\thumbs_up.png or images\thumbs_up.jpg auto-imported displayable based on an existing image.

The new screen "borrows" all the styles of the existing notify screen. If you wanted to separate the two, you'd just need to add a bunch of styles and change the style_prefix 'notify' line.

Edit: Expanded my example to show that the notify variations are interchangeable and because of the tagging, one will replace the other.

I've tested this code and it works.
 
Last edited: