0 Favourites

How do I load a random word

  • 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"!

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • look at my capx here:

  • 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!

  • can you upload a capx, so i can have a look on it

  • Look for the .capx in the attachement

  • 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?

  • Just giving some other options, based on this: [quote:3h7licyx]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.

  • Just giving some other options, based on this: [quote:30hxloqg]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, ...)

  • 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)

  • Thanks a lot, Codah!

    I supposed that dictionaries have a different meaning - thats why I asked it here! I think I will work on with arrays, and maybe I will have a look on "Dictionary" a little later!

    Now I have to go to bed, it is past midnight right now! I will work on tomorrow!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)