playMaker

Author Topic: Creating an in-game search function  (Read 1471 times)

BadgerFarmer

  • Playmaker Newbie
  • *
  • Posts: 11
Creating an in-game search function
« on: July 02, 2023, 08:31:17 AM »
Hi, first post here.

I've been learning the basics of Playmaker for a while now, and have started to create a game. I've got most of the controls and interface in place, except for one feature I want to create but don't really know how.

Within the game, the player has access to a book that they can flick through page-by-page to find clues. So far, the pages are in an array and I've implemented buttons to go forward or backward 1 page, or jump straight to the contents or index pages.

But ideally what I want is a search function, so the player can type in a word into a text input box, and for the game to compare that string to the whole book text looking for matches, then display the results. I don't mind at this stage whether the search only looks for complete words that match exactly, or looks for any instances of the string (e.g. if the player types 'witch' it would also return 'switch' as a result) - whichever is easiest to implement.

I'm really just looking for some pointers how to get the game to scan a large body of text looking for matches. What would be the best way to implement such a function? Is it something I can do using Playmaker alone?

Any advice appreciated. Thanks.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Creating an in-game search function
« Reply #1 on: July 03, 2023, 07:59:46 AM »
Hi.
you can use String Contains to check.
loop thru the pages by using an array (just remember that an array start at 0, not 1)

BadgerFarmer

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Creating an in-game search function
« Reply #2 on: July 03, 2023, 11:13:58 AM »
Thanks for that. I didn't think it could be so straightforward, but yeah, it should work.

I guess that means turning each page of text into a single string, then - as you say - looping through the pages. I should be able to manage that.

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 7618
    • jinxtergames
Re: Creating an in-game search function
« Reply #3 on: July 03, 2023, 02:15:46 PM »
Hi.
You can also use some arrays or array Lists per page so you can have a string for each line.

then use array get next to loop thru the arrays.

BadgerFarmer

  • Playmaker Newbie
  • *
  • Posts: 11
Re: Creating an in-game search function
« Reply #4 on: July 03, 2023, 03:28:02 PM »
OK, thanks. I'll try that out.