How to make Key Scroll viewport AND do another action?[SOLVED]

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
Thomas_Blue
Newbie
Posts: 2
Joined: Fri Jan 26, 2024 3:44 pm
Projects: neonBlue
Github: GallinX
itch: To be Added
Contact:

How to make Key Scroll viewport AND do another action?[SOLVED]

#1 Post by Thomas_Blue »

I am making a text messaging system for my game and need help making the phone screen viewport show the next text message and scroll down at the same time. here are the code sections

Code: Select all

 # The scrollable text message viewport    
        viewport id "vp":
            xoffset 80
            if persistent.iphone:
                yoffset 160
            else:
                yoffset 130
            xsize vp_xsize
            ysize vp_ysize
            mousewheel True
            xadjustment xadj
            yadjustment yadj
            has vbox
            spacing 10

Code: Select all

key "K_RETURN" action Play("sound","audio/SendText.ogg") , If(current_text_num < text_class_size, SetVariable("current_text_num", current_text_num+1),Return)
    

    
    key "mousedown_1" action Function(yadj.change, yadj.value + 10), renpy.restart_interaction
if I set both key values to "K_RETURN" instead of working like I want the Return key does no action at all in game. I know I need the IF statement to finish first then run the yadj function.. how can I make the key "K_RETURN" do both in that order when it's pressed?

Thanks for any help!
Last edited by Thomas_Blue on Sat Jan 27, 2024 1:24 pm, edited 1 time in total.

User avatar
m_from_space
Eileen-Class Veteran
Posts: 1000
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: How to make Key Scroll viewport AND do another action?

#2 Post by m_from_space »

Thomas_Blue wrote: Fri Jan 26, 2024 4:14 pm if I set both key values to "K_RETURN" instead of working like I want the Return key does no action at all in game. I know I need the IF statement to finish first then run the yadj function.. how can I make the key "K_RETURN" do both in that order when it's pressed?
You shouldn't add two keys with the same values to begin with.

Just add the adjustment to the list of stuff to execute when pressing the return key. You may want to change yadj to float("inf") meaning the highest possible number. You do not have to restart interaction in my opinion.

Code: Select all

key "K_RETURN" action [ Play("sound","audio/SendText.ogg") , If(current_text_num < text_class_size, SetVariable("current_text_num", current_text_num+1), Return()), Function(yadj.change, float("inf")) ]

If this doesn't fix the problem, maybe it's because the viewport isn't showing the text in the moment the adjustment should happen. In this case you just can make the screen update it's adjustment with each draw automatically or delay the adjustment with a timer.

Auto adjust (assuming you have a viewport inside):

Code: Select all

screen myscreen():
    # auto adjust as long as the viewport is scrolled down completely
    python:
        if yadj.value == yadj.range:
            yadj.value = float("inf")

User avatar
Thomas_Blue
Newbie
Posts: 2
Joined: Fri Jan 26, 2024 3:44 pm
Projects: neonBlue
Github: GallinX
itch: To be Added
Contact:

Re: How to make Key Scroll viewport AND do another action?[SOLVED]

#3 Post by Thomas_Blue »

Code: Select all

screen myscreen():
    # auto adjust as long as the viewport is scrolled down completely
    python:
        if yadj.value == yadj.range:
            yadj.value = float("inf")
That worked ! thank you!

Post Reply

Who is online

Users browsing this forum: Amazon [Bot]