How do I Pick a random key with a dictionary?

Get help using Construct 2

Post » Sun Nov 22, 2015 8:20 pm

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?
Casus Belli: A reason or cause for war
B
18
S
8
G
5
Posts: 39
Reputation: 4,160

Post » Mon Nov 23, 2015 7:03 am

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.
B
52
S
24
G
6
Posts: 391
Reputation: 7,845

Post » Mon Nov 23, 2015 1:03 pm

SciFiStudios wrote:... 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...?
...
Gearworkdragon wrote: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....

@SciFiStudios..if 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)

Image

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
Image
B
65
S
23
G
7
Posts: 1,502
Reputation: 10,890

Post » Wed Nov 25, 2015 1:58 am

Thanks for the help! You've got me going the right direction now!
Casus Belli: A reason or cause for war
B
18
S
8
G
5
Posts: 39
Reputation: 4,160


Return to How do I....?

Who is online

Users browsing this forum: boybacteria, luckyrawatlucky, nahima and 6 guests