How to make a search bar that when a keyword is searched, it will go to a specific scene.

Before starting, I would like to apologize for the long title. I do not want to be flagged for a vague question. 

Anyways, I am going to explain further for what I mean, if you still don’t understand the question:

Lets say I have 5 scenes:

  1. Main Scene

2)Searchbar Scene

3)Dog Scene

4)Cat Scene

5)Bug Scene

In the Searchbar Scene there is a search bar. If you search up “dog” in the search bar, you will be taken to the dog scene. If you search up “cat” in the search bar, you will be taken to the cat scene. If you search up “bug”, you will be taken to the bug scene. You get the picture.

How do I make a search bar and how can I make it transfer to a specific scene.

If you still don’t understand what I am asking, please specify.

Thank you!

Hi garygusep2,

If I may ask, why do you want to have different scenes to different search values? Will the content be that different? you can pass the search variable to a single scene and decide from there what you want.

If you want your search to be exactly the same of your scene, I think you can use gotoScene:

https://docs.coronalabs.com/api/library/composer/gotoScene.html

composer.gotoScene( "results", options )

change “results” string with your search result.

Please note that I don’t use composer, I use my one code to have different scenes, so I may be wrong.

Regards,

Carlos.

Thanks for replying.

My scenes will be different.

How do I pass the search variable and how do i make a search bar.

a search bar is just a native.newTextField

https://docs.coronalabs.com/api/library/native/newTextField.html

with that, you can have a variable that holds the data you type in the text field.

with that variable you can pass it to the new scene:

local searchresult = "cat" -- Later... local options = { effect = "fade", time = 800, params = { result=searchresult } } composer.gotoScene( "results", options )

if you don’t know how to create a search bar, your problem is knowing the basis of Corona. I really suggest you, to read first the tutorials. if not you will be here on forums for a long time and will halt your work for a lot more than if you read first the tutorials.

Thanks I will try this. I did follow the tutorials but it never cover search bars

We don’t have a specific API for a search bar. But as stated above, the core of a search bar is a native.newTextField(). The result from that is a string. A string is what’s passed to composer.gotoScene() for the scene name. 

You will need to massage the text because scene names are case sensitive and “Cat” and “cat” are different strings. 

Rob

Hi garygusep2,

If I may ask, why do you want to have different scenes to different search values? Will the content be that different? you can pass the search variable to a single scene and decide from there what you want.

If you want your search to be exactly the same of your scene, I think you can use gotoScene:

https://docs.coronalabs.com/api/library/composer/gotoScene.html

composer.gotoScene( "results", options )

change “results” string with your search result.

Please note that I don’t use composer, I use my one code to have different scenes, so I may be wrong.

Regards,

Carlos.

Thanks for replying.

My scenes will be different.

How do I pass the search variable and how do i make a search bar.

a search bar is just a native.newTextField

https://docs.coronalabs.com/api/library/native/newTextField.html

with that, you can have a variable that holds the data you type in the text field.

with that variable you can pass it to the new scene:

local searchresult = "cat" -- Later... local options = { effect = "fade", time = 800, params = { result=searchresult } } composer.gotoScene( "results", options )

if you don’t know how to create a search bar, your problem is knowing the basis of Corona. I really suggest you, to read first the tutorials. if not you will be here on forums for a long time and will halt your work for a lot more than if you read first the tutorials.

Thanks I will try this. I did follow the tutorials but it never cover search bars

We don’t have a specific API for a search bar. But as stated above, the core of a search bar is a native.newTextField(). The result from that is a string. A string is what’s passed to composer.gotoScene() for the scene name. 

You will need to massage the text because scene names are case sensitive and “Cat” and “cat” are different strings. 

Rob