• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Problem with multiple choice questions

D

Dazzy

Guest
Hi, yeah so I've been trying to get some multiple choice questions into my game. The thing it's supposed to do is 1. pick a random question 2. pick four random answers where one of them is the correct one, it shouldn't be choosing two of the same answers. But that's, unfortunately, the case. Here's the code where it picks a random answer out of four, while looking at what the previously chosen answers are.
GML:
if (global.variableans1 == 1 ^^ global.variableans2 == 1)
{
sprite_index = choose(ans1wrong1,ans1wrong2,ans1wrong3);
}
else if (global.variableans1 == 2 ^^ global.variableans2 == 2)
{
sprite_index = choose(ans1correct,ans1wrong2,ans1wrong3);
}
else if (global.variableans1 == 3 ^^ global.variableans2 == 3)
{
sprite_index = choose(ans1correct,ans1wrong1,ans1wrong3);
}
else if (global.variableans1 == 4 ^^ global.variableans2 == 4)
{
sprite_index = choose(ans1correct,ans1wrong1,ans1wrong2);
}
if (sprite_index == ans1correct)
{
global.variableans3 = 1
}
else if (sprite_index == ans1wrong1)
{
global.variableans3 = 2
}
else if (sprite_index == ans1wrong2)
{
global.variableans3 = 3
}
else if (sprite_index == ans1wrong3)
{
global.variableans3 = 4
}
 

curato

Member
yeah that choose isn't going to guarantee you four different answers. In theory they could all be the same answer that is just how random works. You could make an array for the answers then just do a random swap or two and you have them in a random order but each is unique.
 

FrostyCat

Redemption Seeker
The most common community book line for this is pushing into a list and then shuffling.
GML:
var list = ds_list_create();
ds_list_add(list, ans1correct, ans1wrong1, ans1wrong2, ans1wrong3);
ds_list_shuffle(list);
global.variableans1 = list[| 0];
global.variableans2 = list[| 1];
global.variableans3 = list[| 2];
global.variableans4 = list[| 3];
ds_list_destroy(list);
 
Top