This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-11-25 09:41:22

SofiaPontes
New Scratcher
Registered: 2012-11-12
Posts: 1

Help with lists

I'm making a project, and I have a list with questions and a list with answers.
I want to pick a random question till the I run out of questions in the questionlist, and I don't want to repeat the questions.
CAn anyone help please?

Offline

 

#2 2012-11-25 10:13:27

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Help with lists

Try this:

when gf clicked
set [counter v] to [1] 
delete [all v] of [asked v]
repeat (length of [questions v])
if <[asked v] contains (counter)>
repeat until <not <[asked v] contains (counter)>>
set [counter v] to (pick random [1] to (length of [questions v]))
end
end
ask (item (counter) of [questions v]) and wait
if <(answer) = (item (counter) of [answers v])>
change [score v] by [1]
else
change [score v] by [-1]
end
add (counter) to [asked v]
end
stop all
Make sure that the answer to question #4 from the list "questions" is in the 4th position in the "answers" list.

You can change the scoring system to suit your project. Change the +1 to your score with whatever the player gets for correctly answering the question and vice versa for -1.

I hope this helps  smile

Last edited by Prestige (2012-11-25 10:17:50)


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#3 2012-11-25 10:16:58

mathfreak231
Scratcher
Registered: 2012-10-24
Posts: 80

Re: Help with lists

repeat until <(length of [questions v]) = (0)>
set (question_to_ask) to (pick random (1) to (length of [questions v]))
ask (item (question_to_ask) of [questions v]) and wait
add (answer) to [answers v]
delete (question_to_ask) of [questions v]
end
The variables/lists above are needed.

If it can be simplified, please quote and fix.


~This sig is false~
I'm on teh wiki!

Offline

 

#4 2012-11-25 11:28:48

Prestige
Scratcher
Registered: 2008-12-15
Posts: 100+

Re: Help with lists

mathfreak231's script works but isn't ideal, as it deletes the question. My script doesn't delete the question but just the used numbers, so you don't have to add all the questions back in at the start of the project.


"Don't insult someone until you've walked a mile in their shoes. That way, if they don't like what you have to say, you'll be a mile away and still have their shoes  smile  "

Offline

 

#5 2012-11-25 11:36:39

mathfreak231
Scratcher
Registered: 2012-10-24
Posts: 80

Re: Help with lists

Prestige wrote:

mathfreak231's script works but isn't ideal, as it deletes the question. My script doesn't delete the question but just the used numbers, so you don't have to add all the questions back in at the start of the project.

Then make a third table, and put this in a sprite:

when gf clicked
set [iter v] to [1] //Need this variable
repeat (length of [questions_to_add v])
add (item (iter) of [questions_to_add v]) to [questions v]
change [iter v] by (1)
end


~This sig is false~
I'm on teh wiki!

Offline

 

Board footer