How do I Pick a random key with a dictionary?

0 favourites
  • 4 posts
From the Asset Store
Pick Up Items Sound effects for your game, Take them for a ride right now and you will worry no more.
  • I'm working on a game that helps players study US history (amongst other topics, but history will be the first one). When your fighting an enemy i want the game to ask you a question based off of a dictionary (The key is the answer and the value is the statement or question). How can I get it to pick a random key in a dictionary to make this work or is there an easier way to do this that I'm not considering?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Try this input a sprite with a variable and use this command line you can pick n choose which three you like Choose(1,2,3,4) or Random(1,2,3,4) or Floor(1,2,3,4) basically its a random number generator.

    and then you have several condition such as IF variable value at say 3 then use the action to pull that dictionary value.

    I prefer to code a random variable number generator and then putting a condition for each value. this Will help you to control the variable better and If you need to get the variable to do another action you can just put it with it.

  • ... i want the game to ask you a question based off of a dictionary (The key is the answer and the value is the statement or question). How can I get it to pick a random key in a dictionary to make this work...?

    ..

    Try this input .. a variable and use..Choose(1,2,3,4)

    and then you have several condition such as IF variable value at say 3 then use the action to pull that dictionary value.

    I prefer to code a random variable number generator and then putting a condition for each value.

    and..if you have 1000 question...you'll have 1000 conditions....

    you want to use Dictionary ..you need to write keys and values differently...

    keys should look like :"1Question";"2Question"...."1000Question"...

    then if you have variable"Rnd"=5or27or333 ..you can get Rnd&"Question" key

    Second...you need to put your Question&Answer in Value..Use Separator between them...

    (i use # in example)

    then use tokenat to pull out Question&Answer...

    ..and finally..if you don't want to repeat questions..use Array for random values...

    RndDictionary.capx

  • Thanks for the help! You've got me going the right direction now!

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