How do I load a random word

Get help using Construct 2

Post » Wed Feb 11, 2015 7:20 pm

Hi there! First of all - sorry for my english, I am an Austrian!

I am new at Construct 2 and I try to make a "Hangman"-game to learn more about the programm! I am searching for a way to create a list of words. During the game I need a random word out of this list.

I thought I could use the "dictionary"-object for this, but I do not know how it works. I made a dictionary (for example: Name "word1", Type "Text", Initial value "HOUSE") and I tried to use the "Dictionary.Get("...")"-expression, but I always get "0" as a result. I found no way to get the stored word "HOUSE"!
B
3
Posts: 9
Reputation: 193

Post » Wed Feb 11, 2015 8:08 pm

Read this:
yeah, i really like to say that you should "Read this:"
B
12
S
5
Posts: 138
Reputation: 1,490

Post » Wed Feb 11, 2015 9:00 pm

This is how I tried it very often, EyeForcz. It always brings the output "0"!
I use the code:

Set text to Dictionary.Get("lvl" & randomNumber)

to get the stored word, but as I said, I always get "0" (what is also the output when the key does not exist).

At the moment "randomNumber" is a global variable with the "Initial Value" 1!
B
3
Posts: 9
Reputation: 193

Post » Wed Feb 11, 2015 9:12 pm

can you upload a capx, so i can have a look on it
Read this:
yeah, i really like to say that you should "Read this:"
B
12
S
5
Posts: 138
Reputation: 1,490

Post » Wed Feb 11, 2015 9:27 pm

@Earthling here are some other options
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Feb 11, 2015 9:29 pm

Look for the .capx in the attachement
You do not have the required permissions to view the files attached to this post.
B
3
Posts: 9
Reputation: 193

Post » Wed Feb 11, 2015 9:38 pm

codah wrote:@Earthling here are some


I thought it would be easier to create an words-editor, with a dictionary as against arrays?!? Am I wrong with this?
B
3
Posts: 9
Reputation: 193

Post » Wed Feb 11, 2015 10:16 pm

Just giving some other options, based on this:
I am searching for a way to create a list of words. During the game I need a random word out of this list.
I think 'WordArray.at( int(random(WordArray.width)))' is pretty easy.

A 1 dimensional array is a list, so it seems to fit. Now you mention 'editor' so I'm not sure what you want.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Feb 11, 2015 11:17 pm

codah wrote:Just giving some other options, based on this:
I am searching for a way to create a list of words. During the game I need a random word out of this list.
I think 'WordArray.at( int(random(WordArray.width)))' is pretty easy.

A 1 dimensional array is a list, so it seems to fit. Now you mention 'editor' so I'm not sure what you want.


Thanks for your help, Codah!
I thought about arrays at first, and maybe it will be the best way to manage at last!
As I said I am new in Construct2 and I found the "Dictionary", so I thought it could be the "right" way to do what I want!
What I mean with "editor" is a future in-game-option to add new words to the list - not important right now, but a reason why I thought that maybe I should use a dictionary!

I also tried the "How do I get words from a dictionary"-post in this forum! There they also use an array at last, but there is also (a rest?) of a dictionary in the .capx - I only want to find out which way is best (performance, clean code, adding new words in game, ...)
B
3
Posts: 9
Reputation: 193

Post » Wed Feb 11, 2015 11:32 pm

Dictionary does not exactly have the meaning like in real life, so it can be confusing. I'm not saying you can't use it of course. Either way, later you can add editing and saving of the list (e.g. JSON)
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Next

Return to How do I....?

Who is online

Users browsing this forum: duke2704, Yahoo [Bot], Zebbi and 15 guests