remember YScrollValue

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
nananame
Regular
Posts: 72
Joined: Fri Oct 13, 2017 1:40 pm
Contact:

remember YScrollValue

#1 Post by nananame »

A very simple thing is turning into a problem...

I have a screen with a vpgrid. I have a vbar. The scroll works quite nicely with:

Code: Select all

vbar value YScrollValue("id of vpgrid")
All is great.
However, once I close this screen I want a variable to remember where I left off. So that next time I don't start from the top again.

Obviously I should add:

Code: Select all

yinitial y
where the default y = 0

And when closing the screen I should somehow set y = current YScrollValue. And that's where I hit the problem.
How do I get the current value? I tried playing around with ui.adjustment and renpy.get_widget(vpid).yadjustment and all sorts of stuff but somehow I can't piece it together. So, any simple and elegant solution where I can add to the action of a button something like:

action Function(make y=current yadjustment(vpgridid))

??

User avatar
Vladya
Regular
Posts: 34
Joined: Sun Sep 20, 2020 3:16 am
Github: NyashniyVladya
Contact:

Re: remember YScrollValue

#2 Post by Vladya »

Code: Select all

init python:

    _yinitial = .0

screen my_screen:

    hbox:
        align (.5, .5)
        xysize (1280, 720)
        vpgrid id "some_id":
            cols 3
            spacing 30
            yinitial _yinitial
            mousewheel True
            draggable True
            xfill True
            for i in xrange(1337):
                textbutton "{0}".format(i) action Return()
        vbar value YScrollValue("some_id")

    $ yadjustment = renpy.get_widget(None, "some_id").yadjustment
    on "hide" action SetVariable(
        "_yinitial",
        (float(yadjustment.value) / yadjustment.range)
    )

label start:
    while True:
        call screen my_screen
        "Current yinitial is [_yinitial:.2f]."
    return


Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Majestic-12 [Bot]