Page 1 of 1

[solved] Creating multiple Input areas (with DictInputValue)

Posted: Fri Dec 09, 2016 6:56 am
by PineFellow
Hello!

I want to procedurally create a list of buttons and corresponding input fields (i.e. a list of mercenaries that you can personalize a bit)

The problem I'm having is that by using DictInputValue() I'm able to change one value per screen call and I don't know how to use ScreenVariableInputValue() to do this procedurally (it does not have the same visual problem as DictInput).

This is the whole script.rpy for a new test game (tested both on 6.99.12.11.1749 and 6.99.12.1956 with similar results):

Code: Select all

screen button_and_input(button_text, input_val):
    # a simple button and an input field
    textbutton ("prefix " + button_text) action input_val.Toggle()
    input value input_val 

screen main_grid:
    frame align 0.5, 0.5 xysize 300, 430:
        has vbox
        
        default lst = ["list value 1","list value 2","list value 3"]
        # alternatively lst can be a proper dictionary, but indices still have to be integers :(
        # default lst = {0:"dict value 1", 1:"dict value 2", 2:"dict value 3"}
        default ac = range(3)

        default tx1 = "val1"
        default in1 = ScreenVariableInputValue("tx1", default=False)
        use button_and_input(tx1, in1)

        default tx2 = "val2"
        default in2 = ScreenVariableInputValue("tx2", default=False)
        use button_and_input(tx2, in2)

        default tx3 = "val3"

        # this works ONLY as an action, you have to press the following button
        # uncommenting it does not raise any exceptions, though. 
        # $SetScreenVariable("tx3", "NewVal") # does nothing useful either, it seems

        textbutton "change third input" action SetScreenVariable("tx3", "NewVal") # press me! this works
        
        default in3 = ScreenVariableInputValue("tx3", default=False)
        use button_and_input(tx3, in3)

        # proper procedural generation, that does not work so well:
        for i in range (0,2):
            $ac[i] = DictInputValue(lst, i, default=False)
            use button_and_input(lst[i], ac[i])        
        
label start:
    call screen main_grid()
    "that's it"
    return
So this creates
  • 3 buttons with text "prefix val NUMBER", with corresponding different input fields
  • one button "change third input" that changes text of tx3 and its input field accordingly
  • and two buttons with text "prefix list value NUMBER" with corresponding different input fields that can be edited only if "prefix list value" button is pressed as the first action taken on the screen. Every other button group remains fully functional.
Thanks for reading all this!

Issue solved.

Posted: Sat Dec 10, 2016 11:46 am
by PineFellow
Update, solved: so the $ac = DictInputValue(lst, i, default=False) line was breaking variable scope and the proper way... well, the way it works is this:

Code: Select all

        default q_dict = some_function() # returns a dictionary with integer keys and text strings as values
        default inp_val_storage = [DictInputValue(q_dict, i, default=False) for i in q_dict]

        for i in q_dict:
            use button_and_input(q_dict[i], inp_val_storage[i])