Page 1 of 1

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

Posted: Fri Jan 26, 2024 4:14 pm
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!

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

Posted: Sat Jan 27, 2024 10:43 am
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")

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

Posted: Sat Jan 27, 2024 1:26 pm
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!