More usufull variable viewer

A place for Ren'Py tutorials and reusable Ren'Py code.
Forum rules
Do not post questions here!

This forum is for example code you want to show other people. Ren'Py questions should be asked in the Ren'Py Questions and Announcements forum.
Post Reply
Message
Author
User avatar
akakyouryuu
Regular
Posts: 162
Joined: Fri Nov 30, 2012 10:29 am
Contact:

More usufull variable viewer

#1 Post by akakyouryuu »

I think renpy.watch() has several issue.
update only per interaction
don't shown in game menu
don't save watching list

I made more usuful variable viewer.
Please use dynamic_watch() and try it.

this code is public domain.


Code: Select all

init -10 python:

    def dynamic_watch():
        renpy.show_screen("_dynamic_watcher", _layer="debug")

    def _watching_exp(expression):
        return DynamicDisplayable(_dynamic_text, expression=expression)
    def _dynamic_text(st, at, expression):
        try:
            return Text(unicode(renpy.python.py_eval(expression))), .1
        except:
            return Text("Exception"), .1

    if persistent._watch_list is None:
        persistent._watch_list = []

    class Function(Action):
        """
        :doc: other_action

        This Action calls `callable` with `args` and `kwargs`.

        `callable`
            Callable object.
        `args`
            position arguments to be passed to `callable`.
        `kwargs`
            keyword arguments to be passed to `callable`.
        """
        def __init__(self, callable, *args, **kwargs):
            self.callable = callable
            self.args = args
            self.kwargs = kwargs

        def __call__(self):
            self.callable(*self.args, **self.kwargs)

init 1000 python:
    config.locked = False
    config.layers.append('debug')
    config.top_layers.append('debug')
    config.locked = True


screen _dynamic_watcher:
    zorder 2000

    frame:
        background "#0004"
        xfill True
        ymaximum 300
        has vbox
        viewport:
            scrollbars "both"
            mousewheel True
            grid 3 len(persistent._watch_list):
                for i in persistent._watch_list:
                    hbox:
                        textbutton _("x") action [Function(persistent._watch_list.remove, i), Show("_dynamic_watcher", _layer="debug")]:
                            background None
                            xpadding 0
                            ypadding 0
                            xmargin  10
                            ymargin  0
                            yalign .5
                        text "[i]" yalign .5
                    text " -> " yalign .5
                    text _watching_exp(i) yalign .5
        hbox:
            xalign 1.
            textbutton _("add")   action Function(renpy.call_in_new_context, "_watch_list_add")
            textbutton _("close") action [Function(renpy.hide_screen, "_dynamic_watcher", layer="debug"), renpy.restart_interaction]

screen _watch_list_add:
    modal True
    zorder 2500

    frame:
        xfill True
        xmargin .05
        ypos .1
        yanchor 0
        ypadding .05

        has vbox:
            xalign .5
            yalign .5
            spacing 30

        label _("Enter adding expression"):
            xalign 0.5

        hbox:
            xalign 0.5
            input

label _watch_list_add:
    python:
        persistent._watch_list.append(renpy.call_screen('_watch_list_add', _layer="debug"))
    return

Attachments
watch.rpy
(2.85 KiB) Downloaded 244 times

JD_Mortal
Regular
Posts: 37
Joined: Mon Jul 21, 2014 3:01 am

Re: More usufull variable viewer

#2 Post by JD_Mortal »

Nice... Now make an auto-fill for the typing. xD JK.

This really needs a dev-environment, so all this extra code does not have to be within the game itself.

Can't wait to just click somewhere on the screen, select "Add text", "Add button", "Edit text", and then just start typing, and it's all there when you run it, just like you saw it while being made in the dev-environment, but without the editing stuff.

We are getting closer!

User avatar
akakyouryuu
Regular
Posts: 162
Joined: Fri Nov 30, 2012 10:29 am
Contact:

Re: More usufull variable viewer

#3 Post by akakyouryuu »

I set "F12" to the default key for "dynamic watcher".
Attachments
watch.zip
(1.24 KiB) Downloaded 111 times

User avatar
akakyouryuu
Regular
Posts: 162
Joined: Fri Nov 30, 2012 10:29 am
Contact:

Re: More usufull variable viewer

#4 Post by akakyouryuu »

I fixed bugs about text tags
Attachments
watch.zip
(1.28 KiB) Downloaded 150 times

User avatar
akakyouryuu
Regular
Posts: 162
Joined: Fri Nov 30, 2012 10:29 am
Contact:

Re: More usufull variable viewer

#5 Post by akakyouryuu »

Updated.
I improved Keymap compatibility.
Attachments
watch.zip
(1.44 KiB) Downloaded 198 times

Post Reply

Who is online

Users browsing this forum: odysseus93