How to turn on and off player input.

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.
Message
Author
User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: How to turn on and off player input.

#16 Post by trooper6 »

The code I give works for me.
Make a brand new fresh project with this code in your script.rpy

Code: Select all

define e = Character('Eileen', color="#c8ffc8")

screen my_keys():
    #Dismiss keys
    key "mouseup_1" action NullAction()
    key "K_RETURN" action NullAction()
    key "K_SPACE" action NullAction()
    key "K_KP_ENTER" action NullAction()
    key "joy_dismiss" action NullAction()  

# The game starts here.
label start:
    
    e "You've created a new Ren'Py game."
    show screen my_keys()

    e "Once you add a story, pictures, and music, you can release it to the world!"
    hide screen my_keys
    return
Then try to move past the second Eileen line. You won't be able to, proving that this method does actually work. Then we can look at what is going on with your implementation.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

zendavis
Regular
Posts: 46
Joined: Thu Nov 13, 2014 2:03 pm
Contact:

Re: How to turn on and off player input.

#17 Post by zendavis »

Got it working! I love you! Thank you so much!

Xela's method worked. I'm going to try Trooper's right now.
Last edited by zendavis on Wed May 27, 2015 1:41 pm, edited 1 time in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: How to turn on and off player input.

#18 Post by xela »

zendavis wrote:
xela wrote:
zendavis wrote:I'm still able to skip through to the end.
You need to block skipping key as well in that screen if you use that (screen) way. I've added another option while you were posting*
How do I block the skipping key?
http://www.renpy.org/doc/html/keymap.html

Find keybinds that you want to block here and add them to the screen.

zendavis wrote:Like that?
No, just put your animation/transition where """pause 5""" currently is and see if it works for you. Because you still need to somehow know when to restore controls... but you can prolly just use pause statement since they cannot be interrupted anymore.

But as long as it's solved :)
Like what we're doing? Support us at:
Image

zendavis
Regular
Posts: 46
Joined: Thu Nov 13, 2014 2:03 pm
Contact:

Re: How to turn on and off player input.

#19 Post by zendavis »

Code: Select all

init python:
    import pygame
            
label start:
$ pygame.event.set_allowed(None)
$ pygame.event.set_allowed(pygame.USEREVENT)    
stop sound                     #Stops Main Menu music
scene Black space               # SCENE 01 - Black Space Introduction
with Pause(1)
play music "BG_01_Berkley_Heights_B.mp3"
with Pause(4)
scene BG01_Berkley_Heights     
with Dissolve(3.4)
scene BG01_Berkley_Heights
with Pause(1)
$ pygame.event.set_blocked(None)

"I am Samantha Kurosawa and I am freezing. The winter wind cuts through me like a guillotine but I trudge onwards with relentless stubbornness. I will not be stopped tonight." 
That worked!

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: How to turn on and off player input.

#20 Post by xela »

Cool, same thing, just simplified:

Code: Select all

init python:
    import pygame
    
    def kill_all_ui():
        pygame.event.set_allowed(None)
        pygame.event.set_allowed(pygame.USEREVENT)
        
    def restore_ui():
        pygame.event.set_blocked(None)
            
label start:
    $ kill_all_ui()
    # ANY ANIMATIONS OR TRANSITIONS GO HERE.
    $ restore_ui()
You do not have to remember/copy/paste the lines this way.
Like what we're doing? Support us at:
Image

zendavis
Regular
Posts: 46
Joined: Thu Nov 13, 2014 2:03 pm
Contact:

Re: How to turn on and off player input.

#21 Post by zendavis »

trooper6 wrote:The code I give works for me.
Make a brand new fresh project with this code in your script.rpy

Code: Select all

define e = Character('Eileen', color="#c8ffc8")

screen my_keys():
    #Dismiss keys
    key "mouseup_1" action NullAction()
    key "K_RETURN" action NullAction()
    key "K_SPACE" action NullAction()
    key "K_KP_ENTER" action NullAction()
    key "joy_dismiss" action NullAction()  

# The game starts here.
label start:
    
    e "You've created a new Ren'Py game."
    show screen my_keys()

    e "Once you add a story, pictures, and music, you can release it to the world!"
    hide screen my_keys
    return
Then try to move past the second Eileen line. You won't be able to, proving that this method does actually work. Then we can look at what is going on with your implementation.
I tested this. This looks to only work when there is text on the screen. When you remove text and only have images you can still skip through them.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: How to turn on and off player input.

#22 Post by xela »

zendavis wrote:I tested this. This looks to only work when there is text on the screen. When you remove text and only have images you can still skip through them.
It doesn't block user-input, it just reassigns keys while the screen is shown. Just with those keys it is to a degree useless as it will not prevent skipping (everything), will not prevent rollbacks unless implicitly disabled before the menu/preferences and skipping of animations/transitions without additional code.

But it is a LOT more gentle and you have a far better control of what user should be allowed to do... You can also mess with config.keymap/config.default_keymap which will serve in a very similar way and you can disable controls by their functionality instead of specific keys.

There are lots of ways... like with everything else in the Ren'Py. I still think best way was to use ATL for your transitions/animations with a hard or normal pause but whatever works for you :)
Like what we're doing? Support us at:
Image

zendavis
Regular
Posts: 46
Joined: Thu Nov 13, 2014 2:03 pm
Contact:

Re: How to turn on and off player input.

#23 Post by zendavis »

How would I use ATL?

Zen

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: How to turn on and off player input.

#24 Post by xela »

zendavis wrote:How would I use ATL?

Zen
I haven't tested your code so it's hard to rewrite it, I just know that I had (a lot of) issues like yours (animation control vs user input) and always solved these things with atl (it's documented but requires a bit of getting used to and going over this forum sections for examples).

Like I've said, as long as it works for you :)
Like what we're doing? Support us at:
Image

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: How to turn on and off player input.

#25 Post by trooper6 »

I still think hard pauses for graphics are the way to go here, with the key screen only if you need to deal with text. I looked at your original code you said wouldn't work with hard pauses:

Code: Select all

label start:

    stop sound
    scene Black space   
    with Pause(1)
    play music "BG_01_Berkley_Heights_B.mp3"
    with Pause(4)
    $ renpy.pause(3,hard=True)
    scene BG01_Berkley_Heights     
    with Dissolve(3.4)
    $ renpy.pause(3,hard=True)

    "I am Samantha Kurosawa and I am freezing. The winter wind cuts through me like a guillotine but I trudge onwards with relentless stubbornness. I will not be stopped tonight."
Now I was a bit confused about why you had play music with a pause of 4 followed by a pause of 3. I'm going to assume this means you just want a 7 second pause. If you just write it so, you should be fine (I just tested this and it worked for me):

Code: Select all

define odd_dissolve = Dissolve(3.4)

label start:
    stop sound
    scene black #you don't need your own black image, you can use the default 
    $ renpy.pause(1,hard=True)
    play music "BG_01_Berkley_Heights_B.mp3"
    $ renpy.pause(7,hard=True)
    $ renpy.transition(odd_dissolve)
    scene BG01_Berkley_Heights     
    $ renpy.pause(3,hard=True)

    "I am Samantha Kurosawa and I am freezing. The winter wind cuts through me like a guillotine but I trudge onwards with relentless stubbornness. I will not be stopped tonight."
No dismissing allowed because of the hard pauses, but the game keeps going the way you wanted it to.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: How to turn on and off player input.

#26 Post by xela »

I didn't even know one could use a transition over music... with Pause() is supposed to show a displayable for a specified delay, not set a pause of any kind (unless I got confused by documentation, I never used it once in almost 3 years of using Ren'Py).

At the end of the day you can do anything with Screens/ATL/UDD/DD or combination of some/all. Which one is right for the occasion you will only know from experience. But as far as the name of the thread (turning on/off player input), my suggestion does the trick :)
Like what we're doing? Support us at:
Image

wellsgrant
Newbie
Posts: 23
Joined: Mon Feb 11, 2019 10:05 pm
IRC Nick: sidewalkchalk
Deviantart: wellsgrant
Soundcloud: sidewalkchalka
Location: Who even knows at this point...
Contact:

Re: How to turn on and off player input.

#27 Post by wellsgrant »

You could do something like this

Code: Select all

label loop:
    P "{color=#f00}{b}{fast}loop{/b}{/color}{nw}"
    jump loop
Ooo look... a penny!

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: How to turn on and off player input.

#28 Post by trooper6 »

That is an unending loop the program never gets out of. Why would you want that?
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3785
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: How to turn on and off player input.

#29 Post by Imperf3kt »

trooper6 wrote: Thu Jul 18, 2019 12:47 am That is an unending loop the program never gets out of. Why would you want that?
Probably related to this
viewtopic.php?f=8&t=56128&p=515128#p515126

Yet another DDLC inspired game?
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Chiligoat
Regular
Posts: 31
Joined: Thu Mar 21, 2019 7:42 pm
Projects: Witches 4 Hire
Location: Sweden
Contact:

Re: How to turn on and off player input.

#30 Post by Chiligoat »

Sorry for necroing this thread yet again, but for me this is a recurring issue that none of the above solutions have fixed so far.

I would have thought that a modal screen should suffice, but nope.. Modal screen, screen that turns off key inputs, screen with a transparent button that does nothing, a high zorder screen... all of these still allow user input to click straight through all my transforms. Using xela's ui shutdown acts as a hard pause for me through which the transforms refuse to act (and also prevents you from just hard-x:ing out of the application itself, to boot).

It's not just about "oh, the users need to see these nifty animations!" but I'm thinking about people like my partner, who has involuntary neurological finger twitches that frequently make him click when or where he didn't mean to. Ren'py's text rollback is great to fix that stuff, but animations are often one time only, and I just dearly want to stop for like.. eight seconds?
Any takers?

Post Reply

Who is online

Users browsing this forum: No registered users