Discuss Scratch

alethorod
New to Scratch
4 posts

Quizmaster with multiple players and scorekeeping

I want to make a quiz where I can
- first be a “quizmaster” and enter questions, answers and points for each question
- then run the quiz with multiple players and keeping the score

I figured a lot of it out, I think, but I have the most trouble in the multiple teams and scorekeeping.
I want to ask question 1, then team 1 enters the answer and gets it's points, then team 2 etc.

I can't seem to automatically change the team that's answering the question…

Do I have to use a sprite for each team?

This is how far I've gotten. I might have messed it up a bit after fiddeling with it a lot, but still..

https://scratch.mit.edu/projects/572908457

Can anyone give me a gentle push in the right direction?
deck26
Scratcher
1000+ posts

Quizmaster with multiple players and scorekeeping

Why do you have a repeat loop that repeats ‘# of teams’ but then only deals with team 1 variables?

You'd be best using lists for most things. So you have a current question number and a current team number. So you know which question and answer you're asking and which team to ask for the answer and to give points to. Using separate variables for team1, team2 etc is a bad idea.
deck26
Scratcher
1000+ posts

Quizmaster with multiple players and scorekeeping

If you prefer your current way of displaying scores you could still use separate variables but each teamN variable would need to change itself when the corresponding list item changed. For your general script asking questions lists are easier since it saves you repeating code for different variables.
alethorod
New to Scratch
4 posts

Quizmaster with multiple players and scorekeeping

I am not sure how to automatically change variables from team 1 to team 2. I want to ask the same question to each team, so each team can answer and each team be scored. But I don't know to do that automatically.

Something like:
Question 1:
Team 1 answers and have their answer scored
Team 2 answers and have their answer scored
Team 3 answers etc
Team 4 etc
Question 2:

I am a newbie so I might not ask the correct questions…
deck26
Scratcher
1000+ posts

Quizmaster with multiple players and scorekeeping

So you just have nested loops

set question to 1
repeat # of questions
set team to 1
repeat # of teams
ask current team the current question
check answer
if correct
change item ‘team’ of ‘pointslist’
broadcast update and wait
end
change team by 1
end inner repeat
change question by 1
end outer repeat

the update broadcast just resets the score for the current team - a set of nested ifs to allow you to set team1, team2 or whichever.

As you can see the two loops know the current team and question but don't need to access separate variables for them, just lists. The broadcast could be replaced by putting the code in that place inside the inner loop but it is clearer to split it off as a separate bit of script.

Last edited by deck26 (Sept. 21, 2021 18:09:57)

alethorod
New to Scratch
4 posts

Quizmaster with multiple players and scorekeeping

Thank you for your contribution!

I don't really understand it yet though, nor do I get it to work.

Should I keep the current score as a list?
- If so, I don't know how to get it to constantly update and showing the current scores for all the teams.
- If I am to record the score as a variable, I don't understand how to change the variable for “points team 1” etc. Perhaps it is possible to make a variable part of a list somehow?

The “broadcast update”. Where do I find the “update”?

I've tried looking for an example of something similar to see how it can work, but I haven't found one yet. Does anyone have any suggestions for projects I can look at?
deck26
Scratcher
1000+ posts

Quizmaster with multiple players and scorekeeping

alethorod wrote:

Thank you for your contribution!

I don't really understand it yet though, nor do I get it to work.

Should I keep the current score as a list?
- If so, I don't know how to get it to constantly update and showing the current scores for all the teams.
- If I am to record the score as a variable, I don't understand how to change the variable for “points team 1” etc. Perhaps it is possible to make a variable part of a list somehow?


The “broadcast update”. Where do I find the “update”?

I've tried looking for an example of something similar to see how it can work, but I haven't found one yet. Does anyone have any suggestions for projects I can look at?
You're already creating a list of questions and answers so I assume you understand enough about how lists work. So you'd need a new list containing a 0 for each team at the start.

If you're asking team T a question (T has a value 1 to 4, say) and they get it right you update item T of the points list using replace item T of list with (item T of list + P) to add P points.

So displaying the list initially is enough to show this is working. You could also have a list of team names and display these two new lists side by side.

However if you prefer to display the names and scores as you were doing you just need to ensure each team's score value gets updated when they score points. That's where the update broadcast comes in. That doesn't exist yet - you create a new broadcast.

So you'd then have something like

when I receive [update v]
set [team1 v] to (item [1] of [pointslist v] :: list)
set [team2 v] to (item [2] of [pointslist v] :: list)
set [team3 v] to (item [3] of [pointslist v] :: list)
set [team4 v] to (item [4] of [pointslist v] :: list)

It's as quick to reset all values as to go through multiple if blocks to only update the current one.

This is all just basic use of lists to generalise your code. Otherwise all the code gets repeated for each variable and if you need to change something you end up having to change it in multiple places which potentially introduces bugs. I'm not aware of any example projects but it's not that difficult.

Last edited by deck26 (Sept. 22, 2021 09:46:17)

alethorod
New to Scratch
4 posts

Quizmaster with multiple players and scorekeeping

Thanks a bunch! I will try!

Powered by DjangoBB