[Solved] Problem modifying notify() to accept two arguments

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
Errilhl
Regular
Posts: 164
Joined: Wed Nov 08, 2017 4:32 pm
Projects: HSS
Deviantart: studioerrilhl
Github: studioerrilhl
Contact:

[Solved] Problem modifying notify() to accept two arguments

#1 Post by Errilhl »

I'm trying to modify the notify-screen, to accept two variables (so I can change how the notification looks on-the-fly):

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/script.rpy", line 154, in script
    $ renpy.notify("Your relationship with "+str(fM)+" decreased by 1","decrease")
  File "game/script.rpy", line 154, in <module>
    $ renpy.notify("Your relationship with "+str(fM)+" decreased by 1","decrease")
TypeError: notify() takes exactly 1 argument (2 given)

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

Full traceback:
  File "game/script.rpy", line 154, in script
    $ renpy.notify("Your relationship with "+str(fM)+" decreased by 1","decrease")
  File "C:\Program Files (x86)\renpy-6.99.13-sdk\renpy\ast.py", line 827, in execute
    renpy.python.py_exec_bytecode(self.code.bytecode, self.hide, store=self.store)
  File "C:\Program Files (x86)\renpy-6.99.13-sdk\renpy\python.py", line 1764, in py_exec_bytecode
    exec bytecode in globals, locals
  File "game/script.rpy", line 154, in <module>
    $ renpy.notify("Your relationship with "+str(fM)+" decreased by 1","decrease")
TypeError: notify() takes exactly 1 argument (2 given)

Windows-8-6.2.9200
Ren'Py 6.99.13.2919
High School Shenaningans 0.017-(Alpha)
The notification code I'm currently using looks like this:

Code: Select all

screen notify(message, status = None):

    zorder 100
    style_prefix "notify"

    frame at notify_appear:
        text "[message!tq]"

    timer 3.25 action Hide('notify')

    if status:
        if status == 'decrease':
            frame at notify_appear:
                text "[message!tq]" style "red_color"

transform notify_appear:
    on show:
        alpha 0
        linear .25 alpha 1.0
    on hide:
        linear .5 alpha 0.0


style notify_frame is empty
style notify_text is gui_text

style notify_frame:
    ypos gui.notify_ypos

    background Frame("gui/notify.png", gui.notify_frame_borders, tile=gui.frame_tile)
    padding gui.notify_frame_borders.padding

style notify_text:
    properties gui.text_properties("notify")
 
That should work, shouldn't it? The notification code is taken from screens.rpy
Last edited by Errilhl on Wed Nov 15, 2017 4:24 pm, edited 1 time in total.
Currently working on: Image

User avatar
cyanic
Newbie
Posts: 5
Joined: Sun Oct 29, 2017 2:12 am
Github: GMMan
Contact:

Re: Problem modifying notify() to accept two arguments

#2 Post by cyanic »

As the error says, renpy.notify() only takes one argument. Maybe try giving it a tuple?

Source for renpy.notify(): https://github.com/renpy/renpy/blob/mas ... s.py#L2743

User avatar
Scribbles
Miko-Class Veteran
Posts: 636
Joined: Wed Sep 21, 2016 4:15 pm
Completed: Pinewood Island, As We Know It
Projects: In Blood
Organization: Jaime Scribbles Games
Deviantart: breakfastdoodles
itch: scribbles
Location: Ohio
Contact:

Re: Problem modifying notify() to accept two arguments

#3 Post by Scribbles »

you could try to create your own notify screen to take 2 arguments vs modifying the standard one? I'm not sure why that wouldn't work though
Image - Image -Image

Errilhl
Regular
Posts: 164
Joined: Wed Nov 08, 2017 4:32 pm
Projects: HSS
Deviantart: studioerrilhl
Github: studioerrilhl
Contact:

Re: Problem modifying notify() to accept two arguments

#4 Post by Errilhl »

I get that renpy.notify() only takes one argument - since I've modified the screen notify(), I'm assuming that the actual renpy.notify() is NOT the screen, but something else? Or, a separate function somewhere, probably calling the screen inside that function? If so, can I modify the actual renpy.notify()?

I would prefer to be able to modify this, instead of having to code my own, and then create a new function for showing notifications.
Currently working on: Image

Errilhl
Regular
Posts: 164
Joined: Wed Nov 08, 2017 4:32 pm
Projects: HSS
Deviantart: studioerrilhl
Github: studioerrilhl
Contact:

Re: Problem modifying notify() to accept two arguments

#5 Post by Errilhl »

cyanic wrote: Wed Nov 15, 2017 1:40 am As the error says, renpy.notify() only takes one argument. Maybe try giving it a tuple?

Source for renpy.notify(): https://github.com/renpy/renpy/blob/mas ... s.py#L2743
Ah, I get it now. Took me a bit to read through that mess of a page :D

Okay, so that's an internally coded function - can I redefine that function, but keep the content of it? Ie, just allow for it to use two arguments? I'm a little out of my depth here :D
Currently working on: Image

Errilhl
Regular
Posts: 164
Joined: Wed Nov 08, 2017 4:32 pm
Projects: HSS
Deviantart: studioerrilhl
Github: studioerrilhl
Contact:

Re: Problem modifying notify() to accept two arguments

#6 Post by Errilhl »

Okay, I solved this one myself - I was overthinking it...

I modified the screen notify() code to this:

Code: Select all

screen notify(message):

    $ temp_message = None
    $ message_status = None

    zorder 100
    style_prefix "notify"

    if "#" in message:
        $ temp_message = message.split("#")
        $ message = temp_message[0]
        $ message_status = temp_message[1]

    timer 3.25 action Hide('notify')

    if message_status:
        if message_status == "decrease":
            frame at notify_appear:
                text "[message!tq]" style "red_color"
    else:
        frame at notify_appear:
            text "[message!tq]"

transform notify_appear:
    on show:
        alpha 0
        linear .25 alpha 1.0
    on hide:
        linear .5 alpha 0.0


style notify_frame is empty
style notify_text is gui_text

style notify_frame:
    ypos gui.notify_ypos

    background Frame("gui/notify.png", gui.notify_frame_borders, tile=gui.frame_tile)
    padding gui.notify_frame_borders.padding

style notify_text:
    properties gui.text_properties("notify")
Which works fine. I'm quite sure I won't be needing to actually output "#" in the text... If I do, I will have to rethink the separator, but that's for another day
Currently working on: Image

User avatar
cyanic
Newbie
Posts: 5
Joined: Sun Oct 29, 2017 2:12 am
Github: GMMan
Contact:

Re: Problem modifying notify() to accept two arguments

#7 Post by cyanic »

I was thinking something more like this:

Code: Select all

screen notify(message):
    $ msg = message[0]
    $ other_arg = message[1]

...

$ renpy.notify(("My Message", "someArg"))

Errilhl
Regular
Posts: 164
Joined: Wed Nov 08, 2017 4:32 pm
Projects: HSS
Deviantart: studioerrilhl
Github: studioerrilhl
Contact:

Re: Problem modifying notify() to accept two arguments

#8 Post by Errilhl »

Ah, thanks, I wasn't aware that I could do that (push an array or list via containing it). That's good information, and will probably help with other things as well. Now I wish there was a "best answer" or "like" button here :D
Currently working on: Image

Post Reply

Who is online

Users browsing this forum: Google [Bot]