[Solved] While playing your ren'py game, is there a way to output the currently executed code as you're clicking around?

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
henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

[Solved] While playing your ren'py game, is there a way to output the currently executed code as you're clicking around?

#1 Post by henvu50 »

While playing your ren'py game, is there a way to output the currently executed code as you're clicking around?

Let's say you're currently left clicking to move the say text forward. Is there a way to have the code outputted to the console window?

Let's say you click an imagebutton in game, is there a way to have it output the code that's executed as a result of clicking that imagebutton?

Or maybe just show what line # from what file is being executed as you click about in the game?
Last edited by henvu50 on Sat Jun 12, 2021 10:52 pm, edited 1 time in total.

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: While playing your ren'py game, is there a way to output the currently executed code as you're clicking around?

#2 Post by zmook »

There are callbacks on labels, so you can log what labels you've passed through:

Code: Select all

init python:
    def label_callback(name, abnormal):
        renpy.log("label " + name)

    define config.log = "debuglog.txt"
    config.label_callback = label_callback
There are more developer tools documented here: https://www.renpy.org/doc/html/developer_tools.html

If you open the Console, you can use renpy.get_return_stack() to see how you got to wherever you are.

None of this adds up to the full trace capability you seem to asking about, though. But since renpy is Python under the hood, you should be able to import a python tracing library (like https://pymotw.com/2/trace/) if you want one. I haven't tried it, though.
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

drKlauz
Veteran
Posts: 239
Joined: Mon Oct 12, 2015 3:04 pm
Contact:

Re: While playing your ren'py game, is there a way to output the currently executed code as you're clicking around?

#3 Post by drKlauz »

Or just show current line :D

Code: Select all

    frame:
      background "#000A"
      padding (16,8)
      $ctx=renpy.game.context()
      $node=renpy.game.script.lookup(ctx.current)
      text "{}, line: {}".format(node.filename,node.linenumber) outlines [(2,"#000")]
I may be available for hire, check my thread: viewtopic.php?f=66&t=51350

henvu50
Veteran
Posts: 337
Joined: Wed Aug 22, 2018 1:22 am
Contact:

Re: While playing your ren'py game, is there a way to output the currently executed code as you're clicking around?

#4 Post by henvu50 »

drKlauz wrote: Fri Jun 11, 2021 10:05 am Or just show current line :D

Code: Select all

    frame:
      background "#000A"
      padding (16,8)
      $ctx=renpy.game.context()
      $node=renpy.game.script.lookup(ctx.current)
      text "{}, line: {}".format(node.filename,node.linenumber) outlines [(2,"#000")]
Black belt! This is great! Thank you.
None of this adds up to the full trace capability you seem to asking about, though. But since renpy is Python under the hood, you should be able to import a python tracing library (like https://pymotw.com/2/trace/) if you want one. I haven't tried it, though.
Definitely going to try this tomorrow.

User avatar
zmook
Veteran
Posts: 421
Joined: Wed Aug 26, 2020 6:44 pm
Contact:

Re: While playing your ren'py game, is there a way to output the currently executed code as you're clicking around?

#5 Post by zmook »

I just found someone wrote an allegedly proper debugger for renpy. I have not tried it.

https://github.com/Enerccio/renpy-debugger
colin r
➔ if you're an artist and need a bit of help coding your game, feel free to send me a PM

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: While playing your ren'py game, is there a way to output the currently executed code as you're clicking around?

#6 Post by Alex »

henvu50 wrote: Fri Jun 11, 2021 7:54 am ...Or maybe just show what line # from what file is being executed as you click about in the game?
If you'll download a good old Ren'Py (like ver. 6.6.0), you could find the editor.rpy file in the demo-game folder. This code still working...;)

Code: Select all

# This file contains code that's used to display the editor button,
# and the code that launches the editor with the given filename.

# This file can serve as an example of how to use an overlay, I guess.

init:

    # This lets us control if the editor button is shown or not.
    $ show_editor_button = False
    
    python hide:
        
        # This function is called at least one per interaction. 
        def overlay():

            # If we don't want to show the editor button, do nothing.
            if not show_editor_button:
                return
            
            # Figure out the filename and the line number.
            import os.path
            filename, line = renpy.get_filename_line()
            filename = os.path.basename(filename)

            # The function that is called when the button is clicked.
            def clicked():

                # We want to look for the filename in config.gamedir,
                # rather then using the full filename given by
                # get_filename_line. This is because the filename is fixed
                # when the file is compiled, and so may have changed before
                # the script is run. config.gamedir is computed when Ren'Py
                # starts up, and so should always be right.
                fullfn = config.gamedir + "/" + filename

                # If the file exists, then we launch it in the editor, using
                # the undocumented launch_editor function.
                if os.path.exists(fullfn):
                    renpy.launch_editor([ fullfn ], line)

            # Display the button, modifying its look so that it doesn't
            # take up an excessive amount of space.
            ui.button(clicked=clicked,
                      xpos=798, xanchor=1.0, ypos=2, xpadding=6, xminimum=200,
                      background=RoundRect((0, 60, 120, 255), 6),
                      hover_background=RoundRect((0, 80, 160, 255), 6),
                      )

            # The button contains this text. We can't use ui.textbutton,
            # since we want to restyle things.
            ui.text("%s:%d" % (filename, line),
                    style="button_text", 
                    size=14)
            
        # Append the overlay function to the list of overlay functions. 
        config.overlay_functions.append(overlay)

Code: Select all

# The game starts here.
label start:
    $ show_editor_button = True

Post Reply

Who is online

Users browsing this forum: No registered users