How can I make if statement work while a hardpause is happening

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
Nightmarecool2
Newbie
Posts: 7
Joined: Thu Aug 11, 2022 5:38 pm
Contact:

How can I make if statement work while a hardpause is happening

#1 Post by Nightmarecool2 » Sat Oct 01, 2022 4:24 am

This is the code I have written:

show nonstop_debate1
$ renpy.pause(1,hard=True)
if keyboard.is_pressed('n'):
jump correct1
$ renpy.pause(1,hard=True)
hide nonstop_debate1

It works only if I spam press or hold 'n'. I presume that this is due to one of the times I press 'n' it is right after 1 second passes which is when it checks if I pressed 'n'.

How do I make it so that it checks whether I have pressed n once for 2 seconds but also shows the "nonstop_debate1" image while doing that?

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1923
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How can I make if statement work while a hardpause is happening

#2 Post by Ocelot » Sat Oct 01, 2022 4:54 am

Code: Select all

# Reusable screen capturing input. Expects following arguments
#   button - keysym to press: https://www.renpy.org/doc/html/keymap.html
#   target - label to jusmp if answer is correct
#   incorrect_target - optional, label to jump if not answered correctly before timeout
#   time - timeout. After it screen will be hidden and execution continues.
screen input_receiver(button, target, incorrenct_target=None, time=2.0):
    modal True
    key button action Jump(target)
    $ act = Jump(incorrect_target) if incorrect_target else NullAction()
    timer time action [act, Hide("input_receiver")]

# . . .

show nonstop_debate1
# No need to pause. Call Screen already forces an interaction and screen modality prevents anything else from getting events.
call screen input_receiver(button='K_N', target="correct1", time=2.0)
hide nonstop_debate1
Code is not tested, so there might be some errors.
< < insert Rick Cook quote here > >

Nightmarecool2
Newbie
Posts: 7
Joined: Thu Aug 11, 2022 5:38 pm
Contact:

Re: How can I make if statement work while a hardpause is happening

#3 Post by Nightmarecool2 » Sat Oct 01, 2022 5:08 am

I received an error.

This is the traceback:
```
I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/script.rpy", line 32: 'show' is not a keyword argument or valid child for the screen statement.
show nonstop_debate1
^

Ren'Py Version: Ren'Py 8.0.1.22070801
Sat Oct 1 12:05:40 2022
```

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1923
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: How can I make if statement work while a hardpause is happening

#4 Post by Ocelot » Sat Oct 01, 2022 5:23 am

Those are two different parts of code. One is a screen definition and should be outside of any label and other RenPy script.
The second is just the part of script intended to replace yours. A complete code you can test in new project by replacing script.rpy content with this:

Code: Select all

# Reusable screen capturing input. Expects following arguments
#   button - keysym to press: https://www.renpy.org/doc/html/keymap.html
#   target - label to jusmp if answer is correct
#   incorrect_target - optional, label to jump if not answered correctly before timeout
#   time - timeout. After it screen will be hidden and execution continues.
screen input_receiver(button, target, incorrect_target=None, time=2.0):
    modal True
    key button action Jump(target)
    $ act = Jump(incorrect_target) if incorrect_target else NullAction()
    timer time action [act, Return(), Hide("input_receiver")] # Use both Return and Hide to support both call and show

label start:
    show nonstop_debate1
    # No need to pause. Call Screen already forces an interaction and screen modality prevents anything else from getting events.
    call screen input_receiver(button='K_n', target="correct1", time=2.0)
    hide nonstop_debate1
    'incorrect'
    return

label correct1:
    'correct'
    return
Notice that I have changed screen somewhat: there was a one typo and I added Return() to properly end the interaction in case no jump happens.
< < insert Rick Cook quote here > >

Nightmarecool2
Newbie
Posts: 7
Joined: Thu Aug 11, 2022 5:38 pm
Contact:

Re: How can I make if statement work while a hardpause is happening

#5 Post by Nightmarecool2 » Sat Oct 01, 2022 5:35 am

Thanks it worked now!

Post Reply

Who is online

Users browsing this forum: Google [Bot], _ticlock_