[REOPEN] Prevent (text)button from being activated by enter

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
philat
Eileen-Class Veteran
Posts: 1900
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Preventing (text)button from being activated with enter

#16 Post by philat »

I've never had reason to do it so I don't know off the top of my head. But I would assume that whatever you're using for the randomizer button is keying in on that text anyway?

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Preventing (text)button from being activated with enter

#17 Post by mobychan »

I just save the random name in a variable and reload the screen, using the content of the variable as default ^^''

philat
Eileen-Class Veteran
Posts: 1900
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Preventing (text)button from being activated with enter

#18 Post by philat »

Well, in that case isn't there no reason not to use use Return() without the If() part?

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: Preventing (text)button from being activated with enter

#19 Post by mobychan »

philat wrote:Well, in that case isn't there no reason not to use use Return() without the If() part?
You're right, it works^^
BUT I had to switch the order around, since it only works if the Key is defined AFTER the Random button^^

Thank you to all of you ^^

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: [SOLVED] Prevent (text)button from being activated by en

#20 Post by mobychan »

After retesting I realised the "Return()" action won't return any inputted names, so I'm back to square one...

Basically I need a possibility to return the input's value in a custom keymapping

philat
Eileen-Class Veteran
Posts: 1900
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: [REOPEN] Prevent (text)button from being activated by en

#21 Post by philat »

I believe I ran a quick test on this last time, and the variable was stored in _return just fine from what I recall.

User avatar
mobychan
Veteran
Posts: 275
Joined: Fri Apr 24, 2015 6:31 am
Projects: The Chosen - Sakura Pink & Gentian Blue
Organization: Foresoft
Location: Germany
Contact:

Re: [REOPEN] Prevent (text)button from being activated by en

#22 Post by mobychan »

if it reacts on the key

Code: Select all

key "K_RETURN" action Return()
I only get True in _return, even though I inserted something ^^''

my full screen:

Code: Select all

textbutton _("Random"):
        xpos 1018
        ypos 607
        background None
        text_style "ribbon_name_choosing_text_big"
        action [SetVariable("first_name", ""), 
                Return()]
        keyboard_focus False

    vbox:
        at ribbon_name_choosing_movein
        xpos 400
        ypos 510
            
        text "Please select a first name for the main character then press\nenter.":
            style "ribbon_name_choosing_text_big"
        
        input id "input_name":
            default first_name
            length 12
            style "ribbon_name_choosing_text_big"
        key "K_RETURN" action Return()
and I call it like this:

Code: Select all

    call screen ribbon_name_choosing("first_name_choosing")
    $ renpy.log("first: %s" % _return)
    if isinstance(_return, basestring):
        $ first_name = _return

User avatar
jesusalva
Regular
Posts: 88
Joined: Mon Jul 22, 2013 5:05 pm
Organization: Software in Public Interest, Inc.
IRC Nick: jesusalva
Github: pazkero
itch: tmw2
Location: Brazil
Discord: Jesusalva#4449
Contact:

Re: [REOPEN] Prevent (text)button from being activated by enter

#23 Post by jesusalva »

EDIT: You may want to look at viewtopic.php?f=51&t=38080#p412055 to don't need to use _return at all.

I used a couple of magic codes '-'
Would appreciate if someone used anti-magic on them >.>

Code: Select all

            ## Returns the input widget with ID 'input_name' on screen 'screen_name'. 
            textbutton "Submit" action Return(renpy.get_widget("screen_name","input_name"))
Remember to replace the textbutton with the key command (you only care about the action part)

And then, when handling the code, I use this magic code I've found out by coincidence while trying to use ui.input some time ago:

Code: Select all

    ## Gets second arg from Text() object
    $ _return=str(_return.text[1]) # This is magic, don't ask.
Purely magic, a hack, likely to break depending on version, but got the work done.
I have no idea why wrote this code, and I do not advice anyone using it.
But then, I was not working with commission, I was just writing code for fun, as a hobby... Just thought I would share it.
Jesusaves/Jesusalva

Post Reply

Who is online

Users browsing this forum: No registered users