How do I retrieve certain words from a document

Get help using Construct 2

Post » Sat Apr 23, 2016 4:28 pm

Hello! I am making a wordpaste game and in it when the player writes a word the game should check is the word that the player has written in the dictionary and if it is a valid word. I have a document containing all the words of my language but I don't know how to retrieve that document and check is the word valid. Is there a way to do it?
B
4
Posts: 10
Reputation: 220

Post » Sat Apr 23, 2016 5:44 pm

You can use tokencount to see if the word exists in your document after you import your document as a project file.

https://www.scirra.com/manual/126/system-expressions
https://www.scirra.com/manual/141/files

Edit: there is also a find() expression you can use, just discovered that after reading through the system expressions again.
Last edited by oosyrag on Sat Apr 23, 2016 5:49 pm, edited 1 time in total.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Sat Apr 23, 2016 5:45 pm

ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Sat Apr 23, 2016 7:43 pm

What I actually want to do is when a person writes for example a word "screen" the program detects the last 2 letters of that word and writes an entirely new word (which it picks up from the document from the list of words) and that word begins with the last 2 letters of the word that the person entered. Ex. "screEN", "ENtertainment". I've been trying to figure it out but I can't seem to do it. Any suggestions?
B
4
Posts: 10
Reputation: 220

Post » Sun Apr 24, 2016 12:38 am

You can use the expression right(text,2) to get the two right most characters. You can use a dictionary to reference into an array based on those characters.

Read in your words, get the right most characters. Check for that dictionary entry. If is exists, pick the array by UID, push the word onto the array. If it doesn't exist, create a new array, add the entry to the dictionary with the array UID, push the entry onto the array.

Now you just need to grab the last two characters from the input, see if that entry exists in the dictionary, if it does, pick the array by UID, and grab some entry from the array.
ImageImageImage
B
71
S
21
G
231
Posts: 3,688
Reputation: 129,352

Post » Sun Apr 24, 2016 3:34 pm

But how do I save a list of words from .txt to a file format that Construct 2 can work with (like dictionary)?
B
4
Posts: 10
Reputation: 220

Post » Mon Apr 25, 2016 1:42 am

Hey replying on my phone so I can only give a summary, but here goes:

A basic parser of a text file will use the newline token for tokencount and tokenat.

Use a loop to repeat tokencount(textfile,newline) times (repeat however many lines are in the text file). Tokenat(textfile,loopindex,newline) will give you the content of each line.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458


Return to How do I....?

Who is online

Users browsing this forum: ultrafop and 9 guests