Random Question Without REPEAT

0 favourites
From the Asset Store
In this template the music plays without looping in your game
  • Hallo.

    i have a question. i make a trivia quiz with random question. but if we meet the next question, it can be repeat the question.

    example :

    my game = 2 9 6 3 3 4 6 8 9 4 6

    i want to = 5 9 6 7 3 2 1 4 8

    Please help me

  • You can add all questions to an array. Pick random record, display it and then delete it from the array.

  • You can add all questions to an array. Pick random record, display it and then delete it from the array.

    thanks for reply.

    can u explain how to display it then delete it from array? u face a beginner people

  • Then I suggest you start with tutorials, there are lots about using the arrays.

    https://www.scirra.com/tutorials/all

    To add a question to array:

    Array-> Push "Question text"

    To pick a random index:

    System -> set RandomIndexVariable to int(random(array.width))

    To print picked question on the screen:

    TextObject -> set text to array.At(RandomIndexVariable)

    To delete this index from the array:

    Array -> Delete index=RandomIndexVariable

    I also highly recommend using Debug Mode (Ctrl-F4) - it will allow you to monitor the contents of the array, variables etc.

  • Then I suggest you start with tutorials, there are lots about using the arrays.

    https://www.scirra.com/tutorials/all

    To add a question to array:

    Array-> Push "Question text"

    To pick a random index:

    System -> set RandomIndexVariable to int(random(array.width))

    To print picked question on the screen:

    TextObject -> set text to array.At(RandomIndexVariable)

    To delete this index from the array:

    Array -> Delete index=RandomIndexVariable

    I also highly recommend using Debug Mode (Ctrl-F4) - it will allow you to monitor the contents of the array, variables etc.

    the link cant open <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad" />

    but my work its a little bit different.

    for add question -> ajax -> request project file. the script file be marked with "|" for the next question. im using image content and no problem with it.

    for pick random index -> array set value at index to trim(tokenat)AJAX.LastData,index,"|"))

    for print question -> function -> Call "show" (0, trim(tokenat(Array.At(random_number),0,";"))

    so how can i delete my question after the user answer it? <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad" />

    this is my reference for the program youtube.com/watch .

    im very need your help bro because next week ill thesis defence <img src="{SMILIES_PATH}/icon_redface.gif" alt=":oops:" title="Embarrassed" />

  • Scirra website is very slow, the link does work, just try again.

    If you are reading the questions from AJAX, you need to load them all into the array first:

    Array set size to X=0, Y=1, Z=1

    For x=0 to (tokencount(AJAX.LastData, "|")-1) : array Push trim(tokenat(AJAX.LastData, loopindex, "|"))

    Then pick a random index from the array:

    System -> set RandomIndex to int(random(array.width))

    Then print the question:

    function -> Call "show" (array.At(RandomIndex))

    Then delete this index from the array:

    Array -> Delete index=RandomIndex

  • Scirra website is very slow, the link does work, just try again.

    If you are reading the questions from AJAX, you need to load them all into the array first:

    Array set size to X=0, Y=1, Z=1

    For x=0 to (tokencount(AJAX.LastData, "|")-1) : array Push trim(tokenat(AJAX.LastData, loopindex, "|"))

    Then pick a random index from the array:

    System -> set RandomIndex to int(random(array.width))

    Then print the question:

    function -> Call "show" (array.At(RandomIndex))

    Then delete this index from the array:

    Array -> Delete index=RandomIndex

    its work! but when i delete the random_number, it will be delete the question. not variable of random_number if i check on debug layout.

    because the previous command, i use random_number for call the question like :

    set -> random_number to round(random(TOTAL_QUESTION)).

    then i delete it like :

    Array -> Delete index (random_number) from X axis.

    then i push back like :

    push back random_number on X axis.

    *random_number is global variabel

    *total_question is contants global variabel = 30.

  • Sorry, I don't understand your problem.

    My idea was to add all questions to an array, then remove them one by one. This is to ensure that each question is displayed only once.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Sorry, I don't understand your problem.

    My idea was to add all questions to an array, then remove them one by one. This is to ensure that each question is displayed only once.

    i mean, my random function is in the (random_number).

    and the random_number is set to (Array.width) where the array is filled question.

    if i run on debug, the variable of random_number is like : 2 5 9 6 9 4 5 6 3 1...

    it will be duplicate the question. so, im not random the Array.width in this condition.

    how can i delete the variable of random_number after answer the question? like : 2 5 9 6 4 5 3 1...

  • If you remove the question from the array after displaying, you don't have to worry that the values in random_number can repeat!

    Here is an example:

    At first your array looks like this:

    Index 0 - "What is your name?"

    Index 1 - "What is your birth date?"

    Index 2 - "Do you have a pet?"

    Index 3 - "Do you like games?"

    You generate random_number=floor(random(array.width)) and it's 2.

    So you display the question from the array at index 2: "Do you have a pet?"

    Then you delete the record with index 2 from the array.

    After that your array contains these records:

    Index 0 - "What is your name?"

    Index 1 - "What is your birth date?"

    Index 2 - "Do you like games?"

    Then you generate random_number again and the result is 2 again!

    But it's not a problem , because this time the question at index 2 in the array is different! Now it's "Do you like games?"

    And then you remove the question with index 2 and can repeat this until you have no questions left in the array.

    Do you see what I mean?

  • If you remove the question from the array after displaying, you don't have to worry that the values in random_number can repeat!

    Here is an example:

    At first your array looks like this:

    Index 0 - "What is your name?"

    Index 1 - "What is your birth date?"

    Index 2 - "Do you have a pet?"

    Index 3 - "Do you like games?"

    You generate random_number=floor(random(array.width)) and it's 2.

    So you display the question from the array at index 2: "Do you have a pet?"

    Then you delete the record with index 2 from the array.

    After that your array contains these records:

    Index 0 - "What is your name?"

    Index 1 - "What is your birth date?"

    Index 2 - "Do you like games?"

    Then you generate random_number again and the result is 2 again!

    But it's not a problem , because this time the question at index 2 in the array is different! Now it's "Do you like games?"

    And then you remove the question with index 2 and can repeat this until you have no questions left in the array.

    Do you see what I mean?

    I GOT IT!

    the array will be deleted. example : my total question is 30. then if i answer 10 question, the array will be 20 question left. but the problem is the random function on random_number. it still 30 random function on 20 question. the causes will be another question where not displayed.

    example :

    array = (1-10) 2 6 8 4 5

    random_number(random function)= 2 6 8 4 5 (8) (2) 10 (8)

    *the number of "()" its not displayed question.

    how can i deleted the random funtion too?

  • I don't understand what you are trying to say, sorry.

    Can you share your capx?

  • sad <img src="{SMILIES_PATH}/icon_e_sad.gif" alt=":(" title="Sad" />

    of course.

    link on : 4shared.com/file/MXaJketbfi ... ANGAN.html

    u just klik play -> sulit -> and the question will be displayed after u click it.

    u can check on debug mode and se random_number3 and the array for the problem.

    sorry i cant write the link cause reputation problem. can i know ur email?

  • try posting the link without the "https://" part

    or insert spaces in the middle.

  • try posting the link without the "https://" part

    or insert spaces in the middle.

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