[Developer Tool] Dynamic Value Adjuster

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
SypherZent
Veteran
Posts: 362
Joined: Fri Sep 02, 2016 3:14 am
Completed: Multiverse Heroes, Space Hamster in Turmoil
Location: Puerto Rico
Contact:

[Developer Tool] Dynamic Value Adjuster

#1 Post by SypherZent »

Tired of randomly guesstimating offsets for your screen elements that do not perfectly align?
Tired of doing hours of trial-and-error, attempting different values for your script, only to have to wait for reload/recompile between every attempt?

If you answered 'yes' to any of the above, this is the tool for you.

During hundreds of hours of coding sessions, I found myself wasting minutes by the hour waiting for the script to reload so that I could attempt different integer values for things like offsets, stat calibrations, and more. As my game grew, reloading took longer, and I developed a little tool to save me countless hours by allowing me to simply call it with one line from any script, from any game (provided I include the .rpy file temporarily), and allow me to quickly calibrate what I need without having to reload.


So, first, here is the code. Below are the instructions.

Code: Select all




init:
    default arg1 = 0
    default arg2 = 0
    default arg3 = 0
    default arg4 = 0

init python:

    if not "elem_adjust" in config.layers:
        config.layers.append('elem_adjust')

screen elem_adjuster(l1="Arg1",a1=0,l2="Arg2",a2=0,l3="Arg3",a3=0,l4="Arg4",a4=0, alignment=(0.5,1.0)):
    layer "elem_adjust"

    if a1 or a2 or a3 or a4:
        timer 0.05 repeat False action [
            If(a1,[SetVariable('arg1',a1)],[]),
            If(a2,[SetVariable('arg2',a2)],[]),
            If(a3,[SetVariable('arg3',a3)],[]),
            If(a4,[SetVariable('arg4',a4)],[])
        ]

    $ form_list = [arg1,arg2,arg3,arg4]
    $ arg_list = ['arg1','arg2','arg3','arg4']
    $ label_list = [l1,l2,l3,l4]

    frame:
        background Solid("#000000")
        align alignment
        xysize (500,500)

        vbox:
            align (0.5,0.5)
            spacing 18

            for form_idx, form in enumerate(form_list):

                $ lab = label_list[form_idx]
                $ arg = arg_list[form_idx]

                hbox:
                    xalign 0.5
                    spacing 36
                    vbox:
                        align (0.0,0.5)
                        text lab xalign 0.5
                        text str(form) xalign 0.5
                    hbox:
                        yoffset 24
                        xalign 1.0
                        spacing 6

                        $ vbox_list = [[1,-1],[5,-5]]

                        for idx2, val_list in enumerate(vbox_list):

                            vbox:
                                yoffset -24
                                spacing 12

                                for idx, val in enumerate(val_list):

                                    $ str_val = (str(val) if val < 0 else "+"+str(val))
                                    use EA_Button(arg,form,val,str_val)

screen EA_Button(arg,form,val,str_val):
    imagebutton:
        xysize (32,32)
        idle Solid("#ffffff90")
        hover Solid("#ffffff")
        foreground Text(str_val,style="EAdjuster")
        action SetVariable(arg,form+val)



style EAdjuster:
    size 20
    bold True
    yoffset 2
    color "#222"


What the tool does:

1) The tool places a crude UI on your screen, on the highest layer, with labels and values and buttons for you to manually adjust the values required.

2)The tool creates a new layer called "elem_adjust" in your config.layers, and places it at the end to ensure the tool appears above all of your screens. Note that this should be temporary, once you remove the tool the layer will no longer be appended, and if you run a layer setting in init like I do, your layers will no longer have "elem_adjust" present.

Visually, you will see the value you require being adjusted, and the element on the screen moving.
Here is an example of usage:

Code: Select all


screen test_screen():

    frame:
        background "some_image.png"
        padding (0,0)
        align (0.5,0.5)
        offset (arg1,arg2) # <--- Here, I use the arguments from the tool, called arg1, arg2.
        
    use elem_adjuster(a1=100, a2=100) # <-- Here, I call the tool with initial arguments 100, 100. Note that a1 is same as arg1.

Caveat(s): This tool only works with integer values.

Install Instructions: Just copy the code above, paste into a new .rpy file, include the file in your game directory.

Uninstall Instructions: Remove both the .rpy and .rpyc files of the tool from your game directory.

Usage Instructions:

1) In your screen or script, set the values you want to change to arg1, arg2, arg3, or arg4 (4 max possible, can set 4 at the same time).

2) Call the elem_adjuster tool, depending on where you call it, the syntax is different.

From screens:

Code: Select all

    use elem_adjuster(l1="Arg1", a1=0, l2="Arg2", a2=0, l3="Arg3", a3=0, l4="Arg4", a4=0, alignment=(0.5,1.0))
From script:

Code: Select all

    call screen elem_adjuster(l1="Arg1", a1=0, l2="Arg2", a2=0, l3="Arg3", a3=0, l4="Arg4", a4=0, alignment=(0.5,1.0))

You can set, or omit, all of the values. The alignment is the position of the elem_adjuster tool on your UI.
l1 through l4 are the titles of the 4 variables you're editing.

3) IMPORTANT: This tool doesn't set your scripts. Once you SEE the values you need on the tool, go change your arg1, arg2, etc. values to the values indicated by the tool.

4) Remember to remove the line where you call the tool.


Hope this is as helpful to others as it has been to me. ^^
Creator of Multiverse Heroes & Space Hamster in Turmoil

Want me to code your game?
Check my services thread!

User avatar
Prandygame
Newbie
Posts: 16
Joined: Tue Oct 06, 2020 10:10 pm
Completed: Romance Dimensional
Projects: Romance Dimensional 2
Organization: Prandy Game
itch: prandygame.itch.io
Contact:

Re: [Developer Tool] Dynamic Value Adjuster

#2 Post by Prandygame »

I don't understand how it works, change an Arg for a variable that is in a transform like ypos notay and when increasing using the buttons nothing happens.
Could you create a library with atl animations? to make different effects with images, it would be very interesting for newbies like me to learn how to make certain effects.
My first game made in Renpy check it out.
https://prandygame.itch.io/visual-novel-romance

User avatar
SypherZent
Veteran
Posts: 362
Joined: Fri Sep 02, 2016 3:14 am
Completed: Multiverse Heroes, Space Hamster in Turmoil
Location: Puerto Rico
Contact:

Re: [Developer Tool] Dynamic Value Adjuster

#3 Post by SypherZent »

Hmm. Well, this isn't a tool for ATL transformations.

When you are creating screens, sometimes you want to align certain elements that are not properly aligned. Maybe you don't know the correct pixel position, and doing trial and error can take much longer when saving and reloading the script, and looking to see if it's too much to the left or too much to the right.

This tool lets you use variables for the positions/offset data and then you can click the +1, +5, -1, -5 buttons to dynamically move the screen element. Then, no trial and error is required. You use the tool, position the element perfectly in the screen, then only save and reload your game once.

So, this tool is simply for saving time when trying to achieve pixel-perfect positioning of complex screen design elements.

ATL transforms are a totally different topic. ^^

This tool probably won't work for ATL transforms because the ATL transforms are not dynamically defined.
They are stored in Ren'Py memory on init and can't be modified during gameplay.
So, it's only for screen elements.

If you want to properly position ATL transforms, create a screen, place the image you are transforming into the screen, use the tool on the screen's image.
Then, you can know the proper data for perfect positioning. Just use that data in your ATL transform and delete the test screen when you're finished with it.

Post Reply

Who is online

Users browsing this forum: No registered users