Help with no repeats of a random selection in an array and setting animations in a quiz

0 favourites
  • 6 posts
From the Asset Store
Selection frame like in RTS games, works both on mobile and desktop devices.
  • I'm creating a multi-answer quiz game and I'm stuck on a couple of things:

    1. I've used an array to store my questions and answers and have set the questions to appear on screen in a random order but some questions are repeating which I obviously do not want. Is there a way I can tell the array not to pick a question if it's already been used?

    2. When the user presses an answer, how do I get the correct one to turn green and the others to turn red?

    I've attached an image to show how the correct answer is chosen.

    I've been trying to do this for about a week and had no success, so any help would be amazing.

    Thanks.

  • 1. Use advanced random, something called a permutation table to generate a random sequence of numbers then pick the corresponding row from the array.

    2. Wouldn't you just set it to green as an action where you also set it to "Correct", or are you asking how to set it to green in general?

  • Thanks for this. I've managed to get the questions to appear in a random order, so there's no issues here but how do I get it to not repeat a question once it's been asked? I'm using an array to store the questions.

    Secondly, I understand how to get the button to set to green but how do I get the button to set to green on the correct answer? The function checks for the answer using the text object, not the button (sprite). I'm thinking maybe by comparing the Y of the text against the Y of the button but I'm not sure. Any ideas?

    Here's an image if it helps:

  • You have an issue because whatever method you used to pick random rows is producing repeated values. If you use the permutation table as mentioned it creates a shuffled set of numbers with no repeats so you can use this to take values from the array.

    You can send the UID of the sprite clicked through the function as a param, and then within the function if answer is correct select sprite by UID and set it to green.

  • OK thanks - I've had a look into permutation tables and they don't look too scary. Can you tell me how I pull the data from my array into the permutation table?

    Also, I've tried to select the answer button to turn green when the correct one is pressed using UID but all of them are turning green or red at the same time, depending on whether a right or wrong answer was selected. Can you tell me how I'd lay this out correctly in the event sheet, so only the correct answer turns green?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • For the green sprite you need to use a condition in the function 'pick sprite by UID' and the value is the function parameter.

    Create permutation on start of layout and in debug view you can see the order of numbers. Say you have 5 questions and the numbers given are 3,1,2,5,4 then that means question 3 would appear first then question 1 etc.

    You can access the data by setting a global variable for current question number to 'advancedrandom.permutation(0)' that would be the first question so 3 in this case. Then the next question would be advancedrandom.permutation(1) etc, so I guess the number in brackets would be a separate variable that increments as you go onto the next question.

    This number would also relate to the row of the array so lets say for the first question the current question variable number is 3, then you access the array using this array.at(questionnumber) so array.at(3) finds the question.

    So you are pulling two bits of data, the next question from the permutation table and then using this number as the row of the array to take the actual question text.

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