Page 1 of 1

Custom Input Issues - Appending Output

Posted: Sat Sep 17, 2016 11:24 am
by DesertFox
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()

Re: Custom Input Issues - Appending Output

Posted: Sun Sep 18, 2016 1:00 am
by PyTom
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.