[Solved] How to set, change xadjustment & yadjustment in VPGrid. Ui.Adjustment demystified.

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] How to set, change xadjustment & yadjustment in VPGrid. Ui.Adjustment demystified.

#1 Post by henvu50 »

Finding this information was a complete and total nightmare. What a terrible experience. Here's the god damn code, lol.

(scroll down more for info on ui.adjustment and how to use the damn thing.)

Code: Select all

default my_custom_xadjustment = ui.adjustment() #HERE, THIS TOOK ME FOREVER TO FIND
default my_custom_yadjustment = ui.adjustment() #HERE, THIS TOOK ME FOREVER TO FIND

init python:

    def someFuncA():
	# move the VPgrid vertibal bar downwards by 100 pixels ....
	my_custom_yadjustment .change(my_custom_yadjustment .value + 100)  #HERE, THIS TOOK ME FOREVER TO FIND
    
    def someFuncB():
	# move the VPgrid vertibal bar upwards by 100 pixels ....
	my_custom_yadjustment .change(my_custom_yadjustment .value - 100) #HERE, THIS TOOK ME FOREVER TO FIND

     def sumbFuncC():
	# set the vertibal bar's position by value directly
        myadjust_y123.change(500) #HERE, THIS TOOK ME FOREVER TO FIND 

screen that_VPGRID():
  
    vpgrid:

        cols 1
        spacing 0
        draggable True
        mousewheel False
        arrowkeys True
        area (500, 200, 500, 500)
        scrollbars "vertical"

        xadjustment my_custom_xadjustment  #HERE, THIS TOOK ME FOREVER TO FIND
        yadjustment my_custom_yadjustment  #HERE, THIS TOOK ME FOREVER TO FIND

        for i in range(1, 100):
            textbutton "Button [i]":
                xysize (200, 50)
                action nullaction()
ui.adjustment - https://www.renpy.org/doc/html/screen_p ... -functions

Code: Select all

default my_custom_xadjustment = ui.adjustment() #HERE, THIS TOOK ME FOREVER TO FIND
default my_custom_yadjustment = ui.adjustment() #HERE, THIS TOOK ME FOREVER TO FIND

init python:

    def someFuncA():
	print my_custom_yadjustment.range
        print my_custom_yadjustment.value
        print my_custom_yadjustment.step
        print my_custom_yadjustment.page
        print my_custom_yadjustment.adjustable
        print my_custom_yadjustment.changed
        print my_custom_yadjustment.ranged
        print my_custom_yadjustment.force_step
	
	#YOU CAN TYPE THE ABOVE VARIABLES INTO THE CONSOLE (SHIFT O), and see their values instantly
range
The range of the adjustment, a number.

value
The value of the adjustment, a number.

step
The step size of the adjustment, a number. If None, then defaults to 1/10th of a page, if set. Otherwise, defaults to the 1/20th of the range.
This is used when scrolling a viewport with the mouse wheel.

page
The page size of the adjustment. If None, this is set automatically by a viewport. If never set, defaults to 1/10th of the range.
It's can be used when clicking on a scrollbar.
The following parameters control the behavior of the adjustment.

adjustable
If True, this adjustment can be changed by a bar. If False, it can't.
It defaults to being adjustable if a changed function is given or if the adjustment is associated with a viewport, and not adjustable otherwise.

changed
This function is called with the new value when the value of the adjustment changes.
ranged
This function is called with the adjustment object when the range of the adjustment is set by a viewport.

force_step
If True and this adjustment changes by dragging associated viewport or a bar, value will be changed only if the drag reached next step. If "release" and this adjustment changes by dragging associated viewport or a bar, after the release, value will be rounded to the nearest step. If False, this adjustment will changes by dragging, ignoring the step value.

change(value)
Changes the value of the adjustment to value, updating any bars and viewports that use the adjustment.
Last edited by henvu50 on Mon Jun 21, 2021 5:22 pm, edited 5 times in total.

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3794
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Can someone demystify yadjustment value for VPgrid? Very hard to find info on it.

#2 Post by Imperf3kt »

Move your default varWHY inside the screen itself, you want the variable to be a local variable, placing it outside the screen declares it as a global.
You've also got too much indentation in your vpgrid

Code: Select all

screen screen894():
    python:
        varWHY = 50
        
    vpgrid:

        cols 1
        spacing 5
        draggable True
        mousewheel False
        edgescroll (150, 600)
        arrowkeys True
        #I'm expecting this to scroll the vpgrid downwards as I increase the value, so if i set this to 200, the position of what you see in vpgrid should be lowered
        yadjustment varWHY  ## <--- no matter what number I put here, it errors out. there is no documentation anywhere on how this works.
        scrollbars "vertical"

        side_xalign 0.5

        for i in range(1, 100):
            textbutton "Button [i]":
                xysize (200, 50)action [some function]
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

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

Re: Can someone demystify yadjustment value for VPgrid? Very hard to find info on it.

#3 Post by Alex »

Here's the sample for a viewport, try it for vpgrid - viewtopic.php?f=8&t=62469#p543979

cisco_donovan
Newbie
Posts: 16
Joined: Wed Apr 06, 2022 7:31 am
itch: ciscodonovan
Contact:

Re: [Solved] How to set, change xadjustment & yadjustment in VPGrid. Ui.Adjustment demystified.

#4 Post by cisco_donovan »

This just helped me out of a bind- thank you!

Post Reply

Who is online

Users browsing this forum: Google [Bot], voluorem