Hi! i'm trying to learn coding just for fun and I came up with an simple idea for a wordgame. it's gridbased using a 10x8 grid with letterpieces that can be swapped around to match words, pretty similar to how you match 3 pieces in candycrush. so i'm using this tutorial series on youtube https://www.youtube.com/watch?v=YhykrMFHOV4&list=PL4vbr3u7UKWqwQlvwvgNcgDL1p_3hcNn2. I'm using almost the same code as in the videos but change it a bit so it suits my specific needs better. however i've been stuck on a problem when it comes to finding the words, so i have questions. this is my function for finding words `func findwordslengthof3():
for i in width:
for j in height:
if all_pieces[i][j] != null:

``````            if i> 0 && i < width -1:
if  all_pieces[i-1][j] !=null && all_pieces[i+1][j] !=null:

if all_pieces[i-1][j].letter == word[0][0] && all_pieces[i][j].letter == word[0][1] && all_pieces[i+1][j].letter == word[0][2]:
all_pieces[i-1][j].matched = true
all_pieces[i-1][j].dim()
all_pieces[i][j].matched = true
all_pieces[i][j].dim()
all_pieces[i+1][j].matched = true
all_pieces[i+1][j].dim()
``````

"word" is an array of words I made.
the problem I'm having is that with this solution, is that I need to repeat the func for every single word, changing the word[0][..] to word[1][..] and so on. So my first question is if it is possible to make the func check next word in the array by itself without me needing to repeat the code for every word? I tried a solution by my own that looked like this```if all_pieces[i-1][j].letter !=word[0][0]: word += 1 if all_pieces[i][j].letter !=word[0][1]: word +=1 if all_pieces[i+1][j] !=word[0][2]: word +=1```

but it just crashes the game.
My second question is, How do I import a wordlist/dictionary in to the project? And how do i sort it so 3 letters words comes first then 4 letters and so on? I think the most optimal would be if I could divide the words into different arrays according to how many letters they have.

As you might notice I'm really new to coding and most likely have done several major mistakes. I hope i can get an nice answer anyways;-).

in Engine

Hi, I'm no expert either but I think it would be better to do something like this:

Store the data separately from the nodes in an Array of PoolStringArrays to make it easier to access data
Use empty strings instead of null for cells that don't have a letter

``````func find_words():
for row in grid:
var word = row.join(" ")
for other_word in word_array:
if other_word in word:
# do something
``````

You'll also have to do this for all the columns as well. I guess you could either store them in a separate Array or just iterate through the row one and make the strings without the `join()` function.

by (7,530 points)
+1 vote

That's what nested loops are for: Create a loop searching for words with 3, 4, 5... letters, and within this loop, create more loops to do this for all positions in the matrix:

``````func find_words():
for word_length in range (3,9):
for x in range(10):
for y in range(10):
``````

I created a small demo project doing this, including a function to load the words from an external file:

https://github.com/t-karcher/Buchstabensalat

by (1,742 points)