[Solved] Ren'Py logging from a Python block?
Posted: Wed Jun 23, 2021 10:07 am
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
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.
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)
returnBut 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.