Custom statement fails to register\be recognized

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
Pyr0
Newbie
Posts: 20
Joined: Mon Aug 07, 2017 4:34 pm
Contact:

Custom statement fails to register\be recognized

#1 Post by Pyr0 »

I have a file called 01statements.rpy which includes the following python code:

Code: Select all

init python:
        
    def appendParse(lexer):
        textToAppend = lexer.string();
        return textToAppend
        
    def appendExecute(textToAppend):
        narrator(textToAppend)
        ReadLastEntry()
    
    renpy.register_statement("append", parse = appendParse, execute = appendExecute)
My start label is in the file main.rpy:

Code: Select all

label start:
    append "I am appending this text."
When the append statement is executed, this error is displayed:

Code: Select all

[code]
I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/main.rpy", line 2, in script
    append "I am appending this text."
Exception: Sayer 'append' is not defined.

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

Full traceback:
  File "game/main.rpy", line 2, in script
    append "I am appending this text."
  File "C:\Users\My Name\Desktop\Ren'py\renpy\ast.py", line 593, in execute
    who = eval_who(self.who, self.who_fast)
  File "C:\Users\My Name\Desktop\Ren'py\renpy\ast.py", line 509, in eval_who
    raise Exception("Sayer '%s' is not defined." % who.encode("utf-8"))
Exception: Sayer 'append' is not defined.

Windows-7-6.1.7601-SP1
Ren'Py 6.99.12.4.2187
HB 1.0
If I try with a different code:

Code: Select all

label start:
    "hello"
    append "there"


The error becomes:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/main.rpy", line 2, in script
    "hello"
  File "renpy/common/00nvl_mode.rpy", line 293, in do_display
    page = self.clear or nvl_clear_next()
  File "renpy/common/00nvl_mode.rpy", line 252, in nvl_clear_next
    scry = scry.next()
AttributeError: 'StoreModule' object has no attribute 'append'

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

Full traceback:
  File "game/main.rpy", line 2, in script
    "hello"
  File "C:\Users\My Name\Desktop\Ren'py\renpy\ast.py", line 613, in execute
    renpy.exports.say(who, what, interact=self.interact)
  File "C:\Users\My Name\Desktop\Ren'py\renpy\exports.py", line 1147, in say
    who(what, interact=interact)
  File "C:\Users\My Name\Desktop\Ren'py\renpy\character.py", line 877, in __call__
    self.do_display(who, what, cb_args=self.cb_args, **display_args)
  File "renpy/common/00nvl_mode.rpy", line 293, in do_display
    page = self.clear or nvl_clear_next()
  File "renpy/common/00nvl_mode.rpy", line 252, in nvl_clear_next
    scry = scry.next()
  File "C:\Users\My Name\Desktop\Ren'py\renpy\ast.py", line 305, in next
    return self._next.scry()
  File "C:\Users\My Name\Desktop\Ren'py\renpy\ast.py", line 649, in scry
    who = getattr(renpy.store, self.who)
AttributeError: 'StoreModule' object has no attribute 'append'

Windows-7-6.1.7601-SP1
Ren'Py 6.99.12.4.2187
HB 1.0
It seems that my file either gets confused for a say statement or is simply not recognized at all. Even copying and pasting the smartline example directly from the documentation doesn't work, it seems like it recognizes the "line" statement but it still wants the dialogue formatted as a string as usual.

User avatar
vollschauer
Veteran
Posts: 231
Joined: Sun Oct 11, 2015 9:38 am
Github: vollschauer
Contact:

Re: Custom statement fails to register\be recognized

#2 Post by vollschauer »

Usually you put this in a "python early:" block, but I tried the example here: https://www.renpy.org/doc/html/cds.html#example
and it doesn't work either, looks like renpy.register_statement isn't working atm.

btw. maybe using "extend" ?

Code: Select all

label start:
    extend "I am appending this text."

User avatar
Pyr0
Newbie
Posts: 20
Joined: Mon Aug 07, 2017 4:34 pm
Contact:

Re: Custom statement fails to register\be recognized

#3 Post by Pyr0 »

Extend is not quite the same thing I need, I've modified the screen so that it includes a viewport and I wanted to make a few custom statements to control its vertical bar (in this case, append makes the bar jump to the bottom so you don't have to scroll yourself).

Anyway, yep, I feared it was a bug with ren'py itself.


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: Custom statement fails to register\be recognized

#5 Post by Remix »

I tried it in a 01test.rpy with a python early hide: block and had some failures...

Swapped it to a 000test.rpy and am pretty sure it still failed and then, maybe after a delete persistent or full refresh, it suddenly started working and now works fine... odd
Frameworks & Scriptlets:

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: Custom statement fails to register\be recognized

#6 Post by Remix »

btw, on the initial post... using a very basic version with a renpy.say, it works fine here...

000test.rpy

Code: Select all

python early hide:

    def parse_cds(lex):
        return lex.string()

    def execute_cds(o):
        renpy.say("Nobody", o)

    def predict_cds(p):
        return [ ]

    def lint_cds(o):
        pass

    renpy.register_statement('test_cds',
                              parse=parse_cds,
                              execute=execute_cds,
                              predict=predict_cds,
                              lint=lint_cds)
script.rpy

Code: Select all

label start:
    "start"
    test_cds "arg"
    "end"
Frameworks & Scriptlets:

User avatar
vollschauer
Veteran
Posts: 231
Joined: Sun Oct 11, 2015 9:38 am
Github: vollschauer
Contact:

Re: Custom statement fails to register\be recognized

#7 Post by vollschauer »

Remix wrote: Thu Aug 10, 2017 6:29 pm btw, on the initial post... using a very basic version with a renpy.say, it works fine here...
No it does not run with the latest nigtly!

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: Custom statement fails to register\be recognized

#8 Post by Remix »

vollschauer wrote: Fri Aug 11, 2017 2:05 am No it does not run with the latest nigtly!
Ah I see. Ren'py 6.99.12.4.2187 here
Frameworks & Scriptlets:

User avatar
vollschauer
Veteran
Posts: 231
Joined: Sun Oct 11, 2015 9:38 am
Github: vollschauer
Contact:

Re: Custom statement fails to register\be recognized

#9 Post by vollschauer »

I revoke my statement that it isn't working, cause I did the noob mistake and put the python early block in my script.rpy, so yeah it is actually working for me as well
with 6.99.12.4.2187 and latest nightly build....

User avatar
Pyr0
Newbie
Posts: 20
Joined: Mon Aug 07, 2017 4:34 pm
Contact:

Re: Custom statement fails to register\be recognized

#10 Post by Pyr0 »

Using a python early block and it fixed it for me as well. My confusion stemmed from the fact that I thought it said "an early python" block (that is, an init). The "early" modifier for the python statement is also not described at all where it should be. All in all I am just happy to have got it to work, thanks everybody.

Post Reply

Who is online

Users browsing this forum: Google [Bot]