I got a problem in usage of viewport in Ren'py 6.12.1.1501

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
User avatar
Alex
Lemma-Class Veteran
Posts: 3090
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

I got a problem in usage of viewport in Ren'py 6.12.1.1501

#1 Post by Alex »

Hi, folks!
As title says, I got problem with viewport. I need to control the values of its scrollbars. So, I found this thread
http://lemmasoft.renai.us/forums/viewto ... adjustment
and made my viewport like

Code: Select all

python:
    def my_vp():
        xadj = ui.adjustment(value=store.xvalue, changed=store_xvalue)
        yadj = ui.adjustment(value=store.yvalue, changed=store_yvalue)
        ui.side(('c'), xpos=100, ypos=50, spacing=5)
        
        vp = ui.viewport(xadjustment = xadj, yadjustment = yadj, draggable=True, mousewheel=True, xmaximum=400, ymaximum=400, child_size=(800, 600))
        
        ui.fixed()
        ui.image("mainmenu.jpg")
        for button in menu_buttons:
            ui.textbutton (button[0], clicked = button[1], background=None)
        ui.close()
        ui.close()
    config.overlay_functions.append(my_vp)
That was working fine and if "xvalue" or "yvalue" was changed, the viewport was automaticaly changed too.

Then I've changed this code to screen language:

Code: Select all

screen my_scr:
        tag game_field
        zorder 40

        $ xadj = ui.adjustment(value=store.xvalue, changed=store_xvalue)
        $ yadj = ui.adjustment(value=store.yvalue, changed=store_yvalue)

        side "c":
                area (0, 0, game_window_size_x, game_window_size_y)
                
                viewport id "game_field_vp":
                    child_size (area_size_x+20, area_size_y+20)
                    draggable True
                    xadjustment xadj
                    yadjustment yadj
For now, the viewport doesn't change automaticaly when the values of "xvalue" and "yvalue" are changed.
Have I missed smth or used "xadj" and "yadj" in wrong place or... I don't know...?
Desperately need help to fix it...))
Thanks in advance.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: I got a problem in usage of viewport in Ren'py 6.12.1.15

#2 Post by PyTom »

You're using xadj and yadj in the wrong place. By creating it in the screen like this, a new pair of adjustments is created each time the screen is updated - and so it's very likely you're not changing the adjustments that the screen is using.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

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

Re: I got a problem in usage of viewport in Ren'py 6.12.1.15

#3 Post by Alex »

Hm... I tried to move

Code: Select all

        $ xadj = ui.adjustment(value=store.xvalue, changed=store_xvalue)
        $ yadj = ui.adjustment(value=store.yvalue, changed=store_yvalue)
from screen to another place in script, but nothing changed...(
I'm sure, that "xvalue" and "yvalue" are changing during the game... but how should I use them for my viewport - that remains a question.

User avatar
PyTom
Ren'Py Creator
Posts: 16088
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: I got a problem in usage of viewport in Ren'py 6.12.1.15

#4 Post by PyTom »

You can't simply update xvalue. Instead, you want to call xadj.change(xvalue) each time xvalue changes. That will signal the viewport to change.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

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

Re: I got a problem in usage of viewport in Ren'py 6.12.1.15

#5 Post by Alex »

Oh... I would never have thought of smth like that...
So, I moved

Code: Select all

        $ xadj = ui.adjustment(value=store.xvalue, changed=store_xvalue)
        $ yadj = ui.adjustment(value=store.yvalue, changed=store_yvalue)
from screen to start label and put

Code: Select all

        $ yadj.change(yvalue)
        $ xadj.change(xvalue)
right after the line, where "xvalue" and "yvalue" are changed.

And it works like it should! Thank you, PyTom...))

Post Reply

Who is online

Users browsing this forum: No registered users