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

Array quiz game help[SOLVED]

Hello

I wanted to choose a random string (of which there are three) stored in an array to appear in one of three speech bubbles (obj_quiz_answer_A,obj_quiz_answer_B,obj_quiz_answer_C,) then, the next bubble will choose one of the remaining strings and the final bubble will have the last string. Without covering every stipulation, could anyone explain an easier way to do this?

This is the code I have so far in the draw event:
Code:
if question=1{//Switch
draw_set_color(c_purple);
draw_set_font(fnt_score);
draw_text(obj_quiz_speech_bubble.x,obj_quiz_speech_bubble.y,quizarray[0,0])
draw_set_color(c_red);
draw_text(obj_quiz_answer_A.x,obj_quiz_answer_A.y,quizarray[0,1])//I want this to choose 0,1 or 0,2 or 0,3
draw_set_color(c_orange);
draw_text(obj_quiz_answer_B.x,obj_quiz_answer_B.y,quizarray[0,2])//Then this to choose from 2 options depending on what quiz_answer_A chose
draw_set_color(c_green);
draw_text(obj_quiz_answer_C.x,obj_quiz_answer_C.y,quizarray[0,3])//Defaults to last option
}
Thanks in advance
 

CloseRange

Member
well my suggestion is to keep it how you have it now, but randomize the order of the array instead.
Alternatively you can store a second array about what order to draw in.
So maybe have this code in the create event.
Code:
var total_n = 3; // how many 'bubbles' you have
for(var i=0; i<total_n; i++) { // loop through all items
    quizarray_order[i] = 0; // initalize the item in the array to some number
    var set = false;
    while(!set) { // keep doing all this until we find some number that hasn't been used yet
        n = irandom(total_n); // set it to a random number
        set = true;
        for(var j=0; j<i; j++) // check back through the list to see if that number has already been used
            if(quizarray_order[j] == n) set = false; // if the number is already in use, make 'set' false so we can try a new number
    }
    quizarray_order[i] = n; // once out of the loop, we know the number is available, so set it.
}
that should in theory work.
That is a simple code that will make an array of 3 items and set each array index
now in your draw event:
Code:
if question=1{//Switch
draw_set_color(c_purple);
draw_set_font(fnt_score);
draw_text(obj_quiz_speech_bubble.x,obj_quiz_speech_bubble.y,quizarray[0,0])
draw_set_color(c_red);
draw_text(obj_quiz_answer_A.x,obj_quiz_answer_A.y,quizarray[0,quizarray_order[0]])//I want this to choose 0,1 or 0,2 or 0,3
draw_set_color(c_orange);
draw_text(obj_quiz_answer_B.x,obj_quiz_answer_B.y,quizarray[0,quizarray_order[1]])//Then this to choose from 2 options depending on what quiz_answer_A chose
draw_set_color(c_green);
draw_text(obj_quiz_answer_C.x,obj_quiz_answer_C.y,quizarray[0,quizarray_order[2]])//Defaults to last option
}
 
well my suggestion is to keep it how you have it now, but randomize the order of the array instead.
Alternatively you can store a second array about what order to draw in.
So maybe have this code in the create event.
Code:
var total_n = 3; // how many 'bubbles' you have
for(var i=0; i<total_n; i++) { // loop through all items
    quizarray_order[i] = 0; // initalize the item in the array to some number
    var set = false;
    while(!set) { // keep doing all this until we find some number that hasn't been used yet
        n = irandom(total_n); // set it to a random number
        set = true;
        for(var j=0; j<i; j++) // check back through the list to see if that number has already been used
            if(quizarray_order[j] == n) set = false; // if the number is already in use, make 'set' false so we can try a new number
    }
    quizarray_order[i] = n; // once out of the loop, we know the number is available, so set it.
}
that should in theory work.
That is a simple code that will make an array of 3 items and set each array index
now in your draw event:
Code:
if question=1{//Switch
draw_set_color(c_purple);
draw_set_font(fnt_score);
draw_text(obj_quiz_speech_bubble.x,obj_quiz_speech_bubble.y,quizarray[0,0])
draw_set_color(c_red);
draw_text(obj_quiz_answer_A.x,obj_quiz_answer_A.y,quizarray[0,quizarray_order[0]])//I want this to choose 0,1 or 0,2 or 0,3
draw_set_color(c_orange);
draw_text(obj_quiz_answer_B.x,obj_quiz_answer_B.y,quizarray[0,quizarray_order[1]])//Then this to choose from 2 options depending on what quiz_answer_A chose
draw_set_color(c_green);
draw_text(obj_quiz_answer_C.x,obj_quiz_answer_C.y,quizarray[0,quizarray_order[2]])//Defaults to last option
}
That seems to work, although I'm not sure it is randomizing the positions as they all keep appearing in the same order (tested it four times).

Would this be an easy way to implement a second random display of a dfferent set of three answers when the first draw text command is also different [1,1]?
 

CloseRange

Member
do you call randomize() at the start of the game?
if you don't do that you'll never see a change between reruns of the game

EDIT:
you can take the code I have, and make it 2 dimensional and then just have to process repeat in another for loop to have a seperate random occurance for each set of choices
 
do you call randomize() at the start of the game?
if you don't do that you'll never see a change between reruns of the game

EDIT:
you can take the code I have, and make it 2 dimensional and then just have to process repeat in another for loop to have a seperate random occurance for each set of choices
No I haven't been calling that, althnough If you close GMS then reopen it to run the game, will the order also still be the same? Anyway thanks for your help, I've got enough to tinker with and make this work!
 
Top