[Solved] Ren'Py logging from a Python block?

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
Phagocytosis
Newbie
Posts: 7
Joined: Mon Jun 21, 2021 1:27 pm
Projects: Polymath – a simulation-heavy life sim about learning
Location: Netherlands
Discord: Babelismoj#4758
Contact:

[Solved] Ren'Py logging from a Python block?

#1 Post by Phagocytosis »

In short:
I was wondering if there is a way to add a line to the Ren'Py log file (what you would normally do with renpy.log("line for the log file")) while inside a Python block.

Explanation:
The line of code I gave just now does not seem to work inside a Python block; I could of course set up a separate logging file using (for example) the Python logging module, but I would really rather keep it in one place if I'm adding debugging messages in my code, for example.

Perhaps more generally my question could be: is there a way to include Ren'Py code in a Python block? (Like how you use the dollar sign to introduce a small Python 'block', but in reverse.) I read somewhere that this is not advisable, but for something like this, it would seem to be very convenient! Then again, if there is a Python-friendly way to do it inside a Python block that does not rely on Ren'Py-specific code, that would of course be fine as well.

Possible solution:
I just realized that you can use Call("label") as part of an action for a button, and you can normally call a label with an argument as well. Perhaps I could set up a label in regular Ren'Py code with just

Code: Select all

label logMessage(message):
    renpy.log(message)
    return
where message is the argument passed along with the Call function (assuming that works elsewhere, not just as an action for a button, which actually seems like a bold assumption; although even if it doesn't work with that function, there's probably another way to call a label from a Python block).

But that seems a bit hacky (although not extremely so), and even if this would work, I would still like to know if there's a better/more elegant solution.
Last edited by Phagocytosis on Wed Jun 23, 2021 11:29 am, edited 1 time in total.

User avatar
Ocelot
Lemma-Class Veteran
Posts: 2402
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Ren'Py logging from a Python block?

#2 Post by Ocelot »

I am not sure what you are asking. renpy.log is a Python function, and it will not work outside Python block, Python one-liner or other places where Python expression is expected.

Did you set config.log variable to the name of your desired log file?

https://www.renpy.org/doc/html/develope ... #renpy.log
https://www.renpy.org/doc/html/config.h ... config.log
< < insert Rick Cook quote here > >

Phagocytosis
Newbie
Posts: 7
Joined: Mon Jun 21, 2021 1:27 pm
Projects: Polymath – a simulation-heavy life sim about learning
Location: Netherlands
Discord: Babelismoj#4758
Contact:

Re: Ren'Py logging from a Python block?

#3 Post by Phagocytosis »

Whoah, you're right. What happened was that a while back, I was logging from Python blocks, and I started thinking it would be nice if I could log from outside Python blocks (which is silly, because outside Python blocks you only have to put a dollar sign and you can access Python functions). Later on, I probably remembered that fleeting thought I had, and since it would've been silly for me to wonder about this, I must have subconsciously figured it was the other way around, and it worked in Ren'Py code but not in Python code. Sigh.

So I guess that solves it. But I'm still kinda curious about the more general question I came up with in my post up above. Or is that what the renpy. does already? In any event, I'll mark this as [solved]. Thank you. I'll have to hide for a while now until my embarrassment passes.

Post Reply

Who is online

Users browsing this forum: Bing [Bot]