[SOLVED] how to make text editable when clicked

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
midgethetree
Regular
Posts: 39
Joined: Wed Dec 30, 2020 3:51 pm
Completed: Back When, The Mother of Pearls, various jam games
Projects: When Everyone's Watching, Deliberation
Github: midgethetree
itch: midge-the-tree
Discord: rainafc#3353
Contact:

[SOLVED] how to make text editable when clicked

#1 Post by midgethetree »

I've made a screen to be called at the beginning of a new game where (among other things, but for now I'm testing with this as the only thing on the screen) the player is supposed to be able to change a persistent value storing their name.

Since there are other options I want to add to this screen I thought it'd be nice if the input could be stuck inside a button like the save/load page names in the tutorial game, which are uneditable by default but can be toggled between editable and uneditable when clicked on.

What is actually happening is that the input is always editable. When clicked on it's styled as if selected but as soon as I hit a key it becomes unselected again, and it's editable regardless of if I've clicked it.

Here's the current screen:

Code: Select all

screen newgame():

    default playername = FieldInputValue(persistent, 'playername')

    button:
          key_events True
          xalign 0.5
          yoffset 200
          action playername.Toggle()
          input value playername style 'button_text' size 48
Which I call at the beginning of the start label. Ultimately other stuff will be added including a button to return and start the actual game but for now I'm just quitting/exiting to main menu.

I also have tried adding default=False as an argument for FieldInputValue but then it's always uneditable, which is even worse. I can click to make it styled as if selected but it can't ever be edited.

Any ideas what I'm doing wrong?
Last edited by midgethetree on Fri Jan 01, 2021 5:30 pm, edited 1 time in total.

User avatar
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: how to make text editable when clicked

#2 Post by _ticlock_ »

Hi, midgethetree,

I would do the following:

Code: Select all

default persistent.playername = ""
screen newgame():
    default playername = persistent.playername
    default input_on = False

    button:
          key_events True
          xalign 0.5
          yoffset 200
	  if input_on:
              input:
                  style 'button_text' size 48
                  value ScreenVariableInputValue('playername')
              action SetScreenVariable("input_on", False)
          else:
              text playername
              action SetScreenVariable("input_on", True)

User avatar
midgethetree
Regular
Posts: 39
Joined: Wed Dec 30, 2020 3:51 pm
Completed: Back When, The Mother of Pearls, various jam games
Projects: When Everyone's Watching, Deliberation
Github: midgethetree
itch: midge-the-tree
Discord: rainafc#3353
Contact:

Re: how to make text editable when clicked

#3 Post by midgethetree »

I changed your suggestion to:

Code: Select all

default persistent.playername = ""
screen newgame():

    default input_on = False

    button:
        key_events True
        xalign 0.5
        yoffset 200
        if input_on:
            input:
                style 'button_text' size 48
                value FieldInputValue(persistent, 'playername')
        else:
            text persistent.playername style 'button_text' size 48
        action ToggleScreenVariable('input_on)
to get it to correctly update the persistent variable (which is what I want) and have consistent text style (although I might create a new style and reassign both to that), but that does do what I want. Thanks!

After some more tests, it seems the problem with my original attempt has something to do with using FieldInputValue, because my original code works if it's editing a screen variable like so:

Code: Select all

default playername = ""
default pn = ScreenVariableInputValue('playername', default=False)

button:
      key_events True
      xalign 0.5
      yoffset 200
      action pn.Toggle()
      input value pn style 'button_text' size 48
So I could assign the screen variable playername to the persistent variable playername and have the button for starting the game for real also reassign the persistent playername to the screen playername, as an alternative workaround.

I have a working game one way or another, but I'm still curious: why did FieldInputValue's editability not toggle correctly in my original button but ScreenVariableInputValue and FilePageNameInputValue do?

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

Re: how to make text editable when clicked

#4 Post by Imperf3kt »

A workaround could be to make the text editable and use a variable to place an invisible screen or button over top of the text that would block access to the text input field.
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
_ticlock_
Miko-Class Veteran
Posts: 910
Joined: Mon Oct 26, 2020 5:41 pm
Contact:

Re: how to make text editable when clicked

#5 Post by _ticlock_ »

midgethetree wrote: Wed Dec 30, 2020 7:31 pm I have a working game one way or another, but I'm still curious: why did FieldInputValue's editability not toggle correctly in my original button but ScreenVariableInputValue and FilePageNameInputValue do?
I think playername should not be screen variable for FieldInputValue to work correctly. This should work:

Code: Select all

default persistent.playername = 'Test'
default playername = FieldInputValue(persistent, 'playername')
screen newgame():
    button:
          key_events True
          xalign 0.5
          yoffset 200
          action playername.Toggle()
          input value playername style 'button_text' size 48

User avatar
midgethetree
Regular
Posts: 39
Joined: Wed Dec 30, 2020 3:51 pm
Completed: Back When, The Mother of Pearls, various jam games
Projects: When Everyone's Watching, Deliberation
Github: midgethetree
itch: midge-the-tree
Discord: rainafc#3353
Contact:

Re: how to make text editable when clicked

#6 Post by midgethetree »

I found out that I needed to 'define' the FieldInputValue instead of using 'default' for it to still work the second time 'round if the person started another new game in the same play session, but after that small change the code suggested right above worked! Thanks for the help.

Post Reply

Who is online

Users browsing this forum: No registered users