Creating a search bar in a screen (SOLVED)

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
Jack_shandy
Newbie
Posts: 2
Joined: Tue Feb 07, 2017 11:39 pm
Contact:

Creating a search bar in a screen (SOLVED)

#1 Post by Jack_shandy » Mon Nov 13, 2017 1:02 am

Hi Everyone,

I'm creating a game with a built-in phone menu. The player can take out their phone at any time and read social media posts. The phone menu and the main game screen are both active at once, so the player can read new posts that pop up while clicking through the text of the main game at the same time. Like this:

Image

All images are placeholder, obviously.

I want to add a search bar to this menu. The idea is that the player can type in keywords, and based on the keyword they type, specific articles will pop up in the phone - like this:

Image

The question: How can i do this?

I know how to achieve what I want in a normal label, but I can't for the life of me figure out how to do it in a screen. This is the relevant bit of my code at the moment:

Code: Select all

           
screen search:
        tag computer
 	window style style.window["computer"]:
            vbox:
                hbox:
                    button action Show("search") xmaximum 50 xminimum 50 ymaximum 50 yminimum 50 ypadding 10:
                        has hbox spacing 10
                        add "images/gui/searchGlass.png"
                    input default ""  xmaximum 200 xminimum 200
                if _return == "1":
                    text "1 Test success!!!"
                else:
                    text "{b}Article Title{/b}" style style.text["phone"]
                    text "[_return]"
                    text "test Article!" style style.text["phone"]
"_return" is always "None", because it can't actually do anything with what the player types. How can I make it bring up specific, different pieces of text depending on what is typed in the input field? Ideally it would just be constantly checking what's in the input field, and bringing up any article that matches.
Last edited by Jack_shandy on Mon Nov 13, 2017 11:00 pm, edited 1 time in total.

User avatar
Divona
Miko-Class Veteran
Posts: 678
Joined: Sun Jun 05, 2016 8:29 pm
Completed: The Falconers: Moonlight
Organization: Bionic Penguin
itch: bionicpenguin
Contact:

Re: Creating a search bar in a screen

#2 Post by Divona » Mon Nov 13, 2017 1:29 am

"_return" will only return value when you "call" the screen, not show. Use Input Value objects to get result of the input instead:

Code: Select all

default input_result = ""

screen search():
    frame:
        has vbox:
            input value VariableInputValue("input_result")
            text "[input_result]"
Completed:
Image

Jack_shandy
Newbie
Posts: 2
Joined: Tue Feb 07, 2017 11:39 pm
Contact:

Re: Creating a search bar in a screen

#3 Post by Jack_shandy » Mon Nov 13, 2017 10:59 pm

Thank you so much, that works great!

Post Reply

Who is online

Users browsing this forum: Google [Bot]