Page 1 of 1

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

Posted: Fri Jun 11, 2021 7:54 am
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?

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

Posted: Fri Jun 11, 2021 10:01 am
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.

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

Posted: Fri Jun 11, 2021 10:05 am
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")]

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

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

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

Posted: Fri Jun 11, 2021 10:39 am
by zmook
I just found someone wrote an allegedly proper debugger for renpy. I have not tried it.

https://github.com/Enerccio/renpy-debugger

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

Posted: Fri Jun 11, 2021 11:32 am
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