Possible to create a search function?

Get help using Construct 2

Post » Mon Jul 25, 2016 10:12 pm

So, is there a way to build a search bar into a game? Say a player collects tons of items, maybe instead of scrolling through all the items they could use a search bar to find the item they're looking for? Or even further, a keyword search that could show items with certain words contained in the description?

I know it sounds odd, but I'd like to know if this is possible in C2. Thanks.
B
7
S
1
Posts: 33
Reputation: 489

Post » Tue Jul 26, 2016 5:09 am

Yes, search functions are possible... but I think perhaps only with NWjs?

I've used C2 with NWjs before to make some Point of Sale (POS) software - which has a search feature to find products in the database, or customer information etc.

I'm not entirely sure if any search can easily be done without using NWjs, though I'm also probably wrong about that. lol

~Sol
Tired of crappy file hosts that are crappy? Get DROPBOX - https://db.tt/uwjysXJF
Moderator
B
80
S
34
G
40
Posts: 3,029
Reputation: 30,393

Post » Tue Jul 26, 2016 9:20 am

You can do it with any exporter if you use the "find()" expression with some specific keyword.
It all depends on what data structure you are using (arrays ? dictionaries ?...), cycle through them with a function and try to find(keyword).
Find() is a text system expression.

So yes it is possible to create a search function, whatever the export you use is.
It nevertheless depends on the type of data structure you are using and so depends on the implementation of your project.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,317
Reputation: 87,483

Post » Sun Jul 31, 2016 8:27 am

If you are using Arrays for your item collection...you could use the Actions

"Contains value"
This searches the entire array to check if any of the elements contains the given value. For example, you can use this to test if the string "sword" is stored anywhere in the array.

"For each element"
A repeating condition that runs once for each element in the array. This therefore runs width x height x depth times.

and
"Compare current value"
Only valid in a For each element loop, either as a following condition or in a sub-event.

These actions might help you..using a Textbox for search input
Event---> Textbox >On text changed-->
Action1--> Array>For each element -->
Action2--> Compare current value (Textbox.text)

Event--> Array.CurValue = (Textbox.text)
Action--> whatever you want to happen

or something like that
When in doubt..or you are lost in a Zombie apocalypse or someone is giving you a hard time..Remember one thing..... Read the Construct 2 Manual..it will save your life.:)
B
35
S
13
G
8
Posts: 318
Reputation: 7,685

Post » Tue Aug 30, 2016 9:16 pm

Great I will do some tests. Thank you!
B
7
S
1
Posts: 33
Reputation: 489


Return to How do I....?

Who is online

Users browsing this forum: varr and 4 guests