How can I make if statement work while a hardpause is happening
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.
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.
-
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
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?
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?
- Ocelot
- Eileen-Class Veteran
- Posts: 1882
- 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
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< < 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
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
```
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
```
- Ocelot
- Eileen-Class Veteran
- Posts: 1882
- 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
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:
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.
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
< < 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
Thanks it worked now!
Who is online
Users browsing this forum: Google [Bot], Majestic-12 [Bot]