Quiz design with variables

I’m trying to make a quiz that has the following conditions

  1. Answer must be in the range 1 - 9
  2. A Random integer A greater than 0 but less than 10
  3. A Random integer B greater than 0 but less than 10
  4. An operator that can be either + or -
  5. Basically the random integer A plus operator then random integer B should produce Answer

Basically, I cannot get events to satisfy all the above and make and show an equation

Any help will be appreciated. Thanks

I’m not sure what you mean. If the quiz answer is picked at random, it’s not a quiz anymore. :thinking:

What I mean’t to say is I wanted a situation where only two integers are used with either + or - operators to get any answer between 1 and 9. Lets say 15 - 7 = 8 is valid but 22 - 7 is not because the answer is greater than 9. I need a random way to generate the numbers 15 and 7 to meet the condition answer

Well, if A is less than 10 and the operator is -, the total will be less than 10.
If A is more than 10 and the operator is -, B must be more than (A - 10).
If operator is + and total must be less than 10, A + B must be less than 10.

I think you need to decide the operator first, then you can generate possible values for A and B.

To translate the condition “must be less/more than”, you can use the While loop.
While A + B > 10, do Random(B), for instance. The loop will repeat until a satisfactory value is found.
If the game crashes or doesn’t load, it means your loop is not correct.

1 Like

Thanks for the tip. How do you create while loops in gdevelop?

It’s a special event, you’ll find it in the big + icon (top right of the screen).

Hi again. I managed to get the random questions working using “-” for now but I have a problem with getting the show Ans to show up. Please see the screenshot.
And how do I get the numbers to reset each time the correct answer is tapped

Thank you in advance

sTapping is not a string variable so you should convert it with ToString(___)
If you want to reset the numbers, use the change variable action, as usual, with the adequate conditions, of course.

Thanks for the quick response. Basically, I thought the same and even changed the scene variable text for sTapping but the output seems the same. I am very new to GDevelop and have basic programming skills so I may not be explaining well. Is there another way to perform the ToString

What do you mean by another way? :thinking: Write ToString(Variable(name)) and it displays the content of the number variable name as a string.
Share updated events screenshot when you make changes, otherwise it gets confusing really quick.

If your “Show Ans” action doesn’t execute, it means the condition is not met. Remove the condition and see if it works, or if the problem is with the variable itself.