Discuss Scratch

Barborawow
New Scratcher
1 post

Asking random questions and assigning correct answers to them

Hey guys, I am currently making a little Math game, which works on a principle of asking questions (math equations) and based on the correct or incorrect answer it will do some stuff (like raising score etc.).
I could possibly write every question separately and assign a correct answer to them, but that's really confusing and it's unreadable.
I need to find a way, how to ask random questions (so it every time a new game starts won't be in the same order and also so I won't have to write everything separately) and assign a good answer to them.
I tried to go in a way of variables - I made 10 variables, each one was a different question and then tried to make the system ask a random variable, but soon I realised that there is no way to assign a correct answer to a random question.

I know I may be a little confusing, but if you understood my question, is there some way to make this work?
If not, I will just write every question and answer separately and it always will be in the same order.

Thank you for all your answers
deck26
Scratcher
1000+ posts

Asking random questions and assigning correct answers to them

You need to learn to use lists. Then item 5 of the answers list is the answer to item 5 of the questions list. You can use a variable to store the number of a question selected randomly.

You may want a third list which you clear each time you start the project and add the currently selected question number to. So when you choose a random question you choose again if that number is already in the list.
PixelYoshi
Scratcher
100+ posts

Asking random questions and assigning correct answers to them

here is a way to make completely random questions and still have the answers:
whenireceiveaskingsetadding or subtractingtopickrandom1to2ifaddingorsubtracting=1thensetquestion part 1topickrandom1to100setquestion part 2topickrandom1to100setanswertoquestionpart1+questionpart2askjoinwhats joinquestionpart1join plus questionpart2andwaitelsesetquestion part 1topickrandom1to100setquestion part 2topickrandom1toquestionpart1setanswertoquestionpart1-questionpart2askjoinwhats joinquestionpart1join minus questionpart2andwaitifanswer=answerthensaycorrect!for2secselsesayoops, wrong.for2secsbroadcastasking
you can also add multiplication and division easily! hope thats helpful!

Powered by DjangoBB