playMaker

Author Topic: Search into an Array[SOLVED]  (Read 2706 times)

xoart

  • Guest
Search into an Array[SOLVED]
« on: March 16, 2015, 02:52:45 PM »
Hi guys,


I am doing a search box and i would like it to be "autocomplete" or "incremental".

I have an array of string to store the variables, but the problem is that the only usable action i found is "string contains". With this action, if you don't put the exact letters, it will not detect the string.

For exemple, if you have this list:

red
cat
rectangle
rector
cheese

and you typed in "re", using the regular expression, it would find the following matches:

red
rectangle
rector

Do you know how to achieve that ?
« Last Edit: March 30, 2015, 08:06:37 AM by jeanfabre »

IDontKnow

  • Junior Playmaker
  • **
  • Posts: 56
Re: Search into an Array
« Reply #1 on: March 16, 2015, 08:06:06 PM »
Offhand, here's how I would do it:

1: Use a 'Get String Length' action on the string you typed

2: Use 'Array List Get Next' to run through the possible matches array, performing the following steps on each one.

3: Use the integer from step 1 with a 'Get String Left' action to reduce the strings you're trying to match to just the relevant characters at the beginning.

4: Use 'String Compare' to see if there's a match. If there is, add the string to the list of matches.

Let me know if that wasn't a clear explanation and I'll whip up an example package later.
--

xoart

  • Guest
Re: Search into an Array
« Reply #2 on: March 17, 2015, 04:13:50 AM »
The problem with this solution is that at the step 2 you need multiples variables to store the matches. This number is unknow (the software user can add strings to the array, so the matches can be numerous).
As far as i know playmaker does not allow to build variables at runtime, so it wouldn't work.

xoart

  • Guest
Re: Search into an Array
« Reply #3 on: March 17, 2015, 05:09:20 AM »
Maybe if we could make a non case-sensitive search ?
Or a non case-sentive contains action ?

IDontKnow

  • Junior Playmaker
  • **
  • Posts: 56
Re: Search into an Array
« Reply #4 on: March 17, 2015, 04:46:24 PM »
I imagine I'd just store all the matches in their own temporary array, rather than as individual variables.

Regarding a non-case-sentive search action: This could be used to acheive the same effect with an extra step or two: http://hutonggames.com/playmakerforum/index.php?topic=4839.0
--

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Search into an Array
« Reply #5 on: March 18, 2015, 02:56:10 AM »
Hi,

 You only need one temp variable you re use throughout your iteration over each array items. that works.

 Bye,

 Jean

xoart

  • Guest
Re: Search into an Array
« Reply #6 on: March 20, 2015, 03:43:27 AM »
Sorry to answer just now, indeed it works ;-)

Thank you very much !