Using lint properly in Creator-Defined Statements?

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
Aoide
Regular
Posts: 31
Joined: Sat Jun 11, 2011 2:40 am
Contact:

Using lint properly in Creator-Defined Statements?

#1 Post by Aoide » Fri Oct 16, 2015 10:32 pm

I'm currently trying to learn Creator-Defined Statements but I'm stumped as to how to use the lint statement properly. The renpy.error() statements I use never show up when there's a problem, and I can't figure out how to make it give an error when I want it to (eg. telling the user that "X is not a keyword argument or valid child for the statement." if they use a keyword argument for my statement that's not supported).

For example, if my statement is written as:

Code: Select all

my_statement "test1" param1 "value1" param2 "value2"
but "param2" is not a valid keyword I want to return the error:
Error: param2 is not a keyword argument or valid child for the my_statement statement.
Theoretically the lint statement should work something like this:

Code: Select all

def lint_my_statement(o):
	test1,kwargs = o
	
	e = my_error_checking(kwargs) # Returns "param2"
	if e is not None:
		renpy.error("Error: %s is not a keyword argument or valid child for the my_statement statement." %s)
But what do I need to do to get Ren'py to call it? (For what it's worth, the Example in the documents also doesn't seem to call the lint statement.)

Any help on this would be much appreciated because I want to make sure that my code handles errors properly. Thanks!

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Using lint properly in Creator-Defined Statements?

#2 Post by PyTom » Sat Oct 17, 2015 12:52 am

You have to register it when you call register_statement.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
Aoide
Regular
Posts: 31
Joined: Sat Jun 11, 2011 2:40 am
Contact:

Re: Using lint properly in Creator-Defined Statements?

#3 Post by Aoide » Sat Oct 17, 2015 1:14 am

You mean like this?:

Code: Select all

renpy.register_statement("line", parse=parse_smartline, execute=execute_smartline, lint=lint_smartline)
Because that's how I registered it (using "lint=lint_my_statement"). Does it need to be registered in a different way?

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Using lint properly in Creator-Defined Statements?

#4 Post by PyTom » Sat Oct 17, 2015 10:20 am

That should be it. Is lint getting called? I'd suggest having it unambiguously return an error. You can see examples of this working in renpy/common/000statements.rpy
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
Aoide
Regular
Posts: 31
Joined: Sat Jun 11, 2011 2:40 am
Contact:

Re: Using lint properly in Creator-Defined Statements?

#5 Post by Aoide » Sun Oct 18, 2015 7:33 pm

You mean something like this?

Code: Select all

def lint_my_statement(o):
   renpy.error("Return error when called.")
If so, it was one of the first things I tried it didn't give me any errors.

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Using lint properly in Creator-Defined Statements?

#6 Post by PyTom » Mon Oct 19, 2015 12:15 am

That should register a statement. It works for me.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

User avatar
Aoide
Regular
Posts: 31
Joined: Sat Jun 11, 2011 2:40 am
Contact:

Re: Using lint properly in Creator-Defined Statements?

#7 Post by Aoide » Mon Oct 19, 2015 2:01 am

I think I figured out the problem. For some reason I assumed the lint statement would error check every time the project was launched (like it does for Ren'py's native statements, such as when you write an invalid statement--like "grow" instead of "show"--or whatever), but it's only called by manually running the "Check Script (Lint)" command through the launcher. Sorry for making such a basic mistake... I gotta say I'm feeling pretty embarrassed right now.

Is there a way to route errors through the regular error checker like with coding errors (the error screen that comes up during the game and says things like "Parsing script failed." or "An exception has occurred.")? Or is it only able to go through the manually-run Lint check?

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Using lint properly in Creator-Defined Statements?

#8 Post by PyTom » Mon Oct 19, 2015 3:14 pm

I'm not sure. I'll check and see, since this seems like it would be a good thing to have.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Hojoo