Page 1 of 1

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

Posted: Wed Jun 23, 2021 10:07 am
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.

Re: Ren'Py logging from a Python block?

Posted: Wed Jun 23, 2021 11:13 am
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

Re: Ren'Py logging from a Python block?

Posted: Wed Jun 23, 2021 11:29 am
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.