1. Hey! Guest! The 33rd GMC Jam will take place between May 23rd, 12:00 UTC (Friday noon) and May 27th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

Array quiz game help[SOLVED]

Discussion in 'Programming' started by Mr Awesome, Mar 15, 2019.

  1. Mr Awesome

    Mr Awesome Member

    Joined:
    Dec 14, 2017
    Posts:
    80
    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
     
  2. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    693
    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
    }
     
    Mr Awesome likes this.
  3. Mr Awesome

    Mr Awesome Member

    Joined:
    Dec 14, 2017
    Posts:
    80
    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]?
     
  4. CloseRange

    CloseRange Member

    Joined:
    Jul 2, 2016
    Posts:
    693
    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
     
    Mr Awesome likes this.
  5. Mr Awesome

    Mr Awesome Member

    Joined:
    Dec 14, 2017
    Posts:
    80
    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!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice