How do I import a dictionary of words into my game?

Get help using Construct 2

Post » Tue Jan 05, 2016 9:51 am

Hi all,

I want to create an auto-runner that uses real words to influence terrain generation. My idea is to create pieces of the environment using only ONE Sprite that has 26 frames (representing the entire pool of the English alphabet).

Example:
The word "CARS" is selected and stored in an Array. The game will loop through the array spawning instances of "Sprite" and setting the frame to the equivalent number in alphabet (-1).

"CARS"

Image

For 1 to TotalLettersInWord
-> Spawn Sprite at XY
-> Set Frame to WordArray[CurrentLetter]
-> Add 1 to CurrentLetter

All sprites will be moving to the Left with behaviour "Destroy outside of layout"

Once the last letter has been spawned it goes back to the first letter, looping indefinitely (another part of the game will change the word).

I am using this method because I think it will be an interesting way to create patterns within the game's landscapes based on the patterns in word construction in the English language, i.e., vowels are only used after certain letters, and certain combinations NEVER come up, such as X followed by R.

SO MY QUESTION IS - What is the best method of creating a list / table of words that the game chooses from? I want to be able to sort them by character length, but other than that I could practically include a whole dictionary as long as it wouldn't slow the game down to a crawl. Any ideas?
B
8
S
2
Posts: 55
Reputation: 676

Post » Tue Jan 05, 2016 11:07 am

Actually, using the dictionary object would be perfect for this..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Jan 05, 2016 11:09 am

LittleStain wrote:Actually, using the dictionary object would be perfect for this..


Oh my.. There's a dictionary object?... I think I have been "thinking around the problem" and overlooked something major...
B
8
S
2
Posts: 55
Reputation: 676

Post » Tue Jan 05, 2016 3:16 pm

I'd use an array. It's not value pairs you are dealing with, but just single entries. It's also easier to access. Dictionaries are not ordered, you can't access entries randomly.
So just create an array with size (words, 1, 1) and then fill the words.
Construct 2 only offers sorting alphabetically as far as I can see. So if you want to quickly be able to access words with a specific length, you could for example sort your words by length right from the start and then remember where are words with length x. Another way would be creating multiple arrays (from the same object), one for each word length (give them an instance variable) and then selecting the appropriate array.

Maybe there is also a data structure plugin that let's you perform some fast searches, but as far as I can see, your wordlist won't change once it's in a game, so theres probably no need for expensive searches.
Last edited by mindfaQ on Wed Jan 06, 2016 4:48 pm, edited 2 times in total.
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: 787
Reputation: 3,786

Post » Tue Jan 05, 2016 4:30 pm

mindfaQ wrote:Dictionaries are not ordered, you can't access entries


???

Doesn't the tokenat() expression work for that, or am I misunderstanding you?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Jan 06, 2016 4:53 pm

LittleStain wrote:Doesn't the tokenat() expression work for that, or am I misunderstanding you?

My sentence was missing a word. Wanted to say that you can't access a random key from the dictionary (or can you, aside from the "for each key"-loop?).

And not sure what you want to do with tokenat. Did you want to store keys like "4" for 4 letter words, "5" for five letter words and give the keys values like "park;east;gone;..."? I don't see an advantage over the array then, if anything I think it would be slower than just grabbing a value directly.
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: 787
Reputation: 3,786


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests