Custom Input Issues - Appending Output

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
User avatar
DesertFox
Regular
Posts: 196
Joined: Sun Jul 28, 2013 1:29 pm
Completed: Over The Hills And Far Away
Projects: My Little Dictator
Organization: WarGirl Games
Contact:

Custom Input Issues - Appending Output

#1 Post by DesertFox » Sat Sep 17, 2016 11:24 am

I'm trying to append text in a custom input button in a screen. Basically for phone numbers with extensions, I want to add a dash after three numbers are entered. However there are issues when it comes to using backspace and the appended value then pulling through for booleans to make use of. I've got the dash appearing after three numbers and the backspace works correctly some of the time, but I'm not certain what the final output is. Perhaps I'm misunderstanding something quite basic when it comes to using functions with input. Any ideas?

*'entervar' is a simple True/False variable that relies on K_ENTER

Code: Select all

default phone = ""

init python:
    def phone_func(newstring):

        def format():
            firstphone = newstring
            firstphone = firstphone + "-"
            store.phone = firstphone
            store.entervar = False
            renpy.restart_interaction()

        def backspace():
            firstphone = newstring
            firstphone = firstphone[:-2]
            store.phone = firstphone
            store.entervar = False
            renpy.restart_interaction()

        def backspacenorm():
            firstphone = newstring
            firstphone = firstphone[:-1]
            store.phone = firstphone
            store.entervar = False
            renpy.restart_interaction()
        
        firstphone = newstring
        if (len(firstphone) == 3):
            format()
        
        if (len(firstphone) == 4):
            backspace()

        ui.keymap(K_BACKSPACE=backspace)

screen phone_input():
    vbox:
        button:
            id "phone_input1"
            xysize (1100,55)
            action NullAction()
            add Input(default=phone, changed=phone_func, length=8, button=renpy.get_widget("phone_input","phone_input1"))

        if phone == "555-5555" and entervar:
            timer 0.25 action Play("sound2", "se/boop.ogg")
        elif phone is not "555-5555" and entervar:
            timer 0.25 action Play("sound2", "se/mork.ogg")
        else:
            timer 0.25 action NullAction()

User avatar
PyTom
Ren'Py Creator
Posts: 15893
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Custom Input Issues - Appending Output

#2 Post by PyTom » Sun Sep 18, 2016 1:00 am

I'd suggest the best way to do this would be to create your own subclass of InputValue, and override the set_text (and maybe get_text) variables to do what you want.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
"Silly and fun things are important." - Elon Musk
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Google [Bot]