# How do I check if an array contains some words?

Get help using Construct 2

### » Sat Nov 29, 2014 5:44 am

Hi there,

I'm not too good with arrays (yet... ), so I hope someone can help me out here...
I'm working on a project in which a player inputs some words; these words are then added to an array.
Then a second player adds new words, but he has to use all the words that are already added to the array, therefore I want to check if all of the words in this array are used in some textfield.

The textfield may contain other words, but ALL of the words in the array should be used in the textfield.
I hope I'm making sense here...

B
61
S
26
G
13
Posts: 96
Reputation: 11,211

### » Sat Nov 29, 2014 9:30 am

add adds the words to the array
finish and compare will finish the "sentence" and compare if all words from the last finish and compare were present
note: you might want to add a lowercase conversion to not differentiate between "word" and "Word"
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

### » Sun Nov 30, 2014 7:27 am

Hi mindfaQ,

thanks a lot for the work you've put into this example!!
I've been able to reproduce the project (simply by typing what YOU typed )
Now I'll have to try to figure out what's really happening here...as I mentioned in my post: I'm not too good at arrays...

Any tutorials or 'reading stuff' you could suggest on arrays?

Thanks again!!
B
61
S
26
G
13
Posts: 96
Reputation: 11,211

### » Sun Nov 30, 2014 12:52 pm

In this example the array is used just like a spread sheet. So imagine one.

First column = word
Second column = number of times it was present in the previous sentence
Third column = number of times it is present in the current sentence
(remember: first column has the Y-index 0)
Each word has its own row

* event 2: checks if the word can be found in any cell in the spread sheet (was already present in the previous sentences, so to say)
* event 3: if it does, it loops through all rows (X) and looks in the first column, if the word matches (this is to find out the row's index, which contains the word)
then it adds 1 to the word count in the third column
* event 4: if the word is not contained, the word gets a new row for its own (that's what the push does); since it is a new word, it was not contained in the previous sentence, so the word count in column 2 is 0 and in column 3 is 1

* event 5-6: just loops through the textbox and runs the add_words function for each word; use lowercase(tokenat...) to prevent discerning between Word, word and WORD.

* event 7 and following will do the check, if all words from the previous sentence are contained in the new sentence
* event 8: loops through each row (= each word)
* event 9: if the word was contained at least as many times in the new sentence as in the old one -> everything is fine, the values are set in a way, that the word count of the new sentence becomes the word count for the old sentence
* event 10: if a word was missing one or more times, it adds the amount of times it was missing to the variable wrong
* event 11: checks if no word was missing and throws a success message
* event 12: if at least 1 word was missing, it throws an error message

check the expressions for arrays, if you don't understand one of the actions: https://www.scirra.com/manual/108/array
most important are imo array.at(x,y,z) to read values from the array and, when looping, array.curx, array.cury and array.curz. Width, heigth, depth can help too, but were not really needed in this case.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 788
Reputation: 3,788

### » Wed Dec 03, 2014 10:04 am

Hi mindfaQ,

At the moment I'm working on an other project.
As soon as I revert to this project again, I'll try to follow/understand what you're doing in attached project.

THANKS!
B
61
S
26
G
13
Posts: 96
Reputation: 11,211