Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Lists and variables question
- runger
-
12 posts
Lists and variables question
I figured out how to use lists and variables to pick a random item from the list and preform an action based on the selection. My question is, is there a way to block a selection once it has been made? For instance, if the first time the game selects item 2 from the list I want to make it so item 2 can no longer be selected the next time that a selection is made. I also want to be able to repeat this until all selections have been made. That way all selections can only be made once, but in a completely random order.
Here's a link to my project, so that you can see what I have so far.
http://scratch.mit.edu/projects/45814060/
Here's a link to my project, so that you can see what I have so far.
http://scratch.mit.edu/projects/45814060/
Last edited by runger (Jan. 31, 2015 15:26:07)
- powercon5
-
1000+ posts
Lists and variables question
you could make a list with
make it so if it picks a item in that list it picks again
or make it remove a item from the list that is picked
(things picked :: list)and
make it so if it picks a item in that list it picks again
or make it remove a item from the list that is picked
Last edited by powercon5 (Jan. 31, 2015 16:04:39)
- runger
-
12 posts
Lists and variables question
I can make a picked list fairly easily, but I'm not able to get that to help. At first I was trying to figure out a way to simply delete an item once picked. However, I don't seem able to get that to work since as soon as one item is deleted all the other items change places on the list and I can only get it delete based on place number not item name.
- Imaginary_Numbers
-
42 posts
Lists and variables question
1. Make a list with all the items that could be picked in it.
2. Duplicate this script so that there are 2 scripts with the same item in them
3. Run the normal script except right where it performs a selection tell it to delete that item from list 1. List 2 is simply a backup so that you don't loose all the items. It will probably look something like this:
2. Duplicate this script so that there are 2 scripts with the same item in them
3. Run the normal script except right where it performs a selection tell it to delete that item from list 1. List 2 is simply a backup so that you don't loose all the items. It will probably look something like this:
when green flag clickedAfter all the selection have been picked use this script to put them back into list 1 from list 2:
set [selection # v] to (pick random (1) to (length of [list 1 v]))
perform action based on the item selected
delete (selection #) of [list 1 v]
set [counter v] to [1]
repeat (length of [list 2 v])
add (item (counter) of [list 2 v]) to [list 1 v]
change [counter v] by [1]
end
- runger
-
12 posts
Lists and variables question
Imaginary Number. I tried something very similar to your top script. (I think) Except it didn't delete the item the way I thought it would. I have a variable called choice and a list called color. This is what I tried first.
.
.
when this sprite clicked
set [(choice) v] to [ (item (random v) of [color v])]
broadcast [(choice) v]
delete ((choice) v) of [ color v]
- runger
-
12 posts
Lists and variables question
I also tried going a completely different route, where i basically toggled each selection to off by renaming them after they were selected. This mostly works. The problem I'm having now is that the computer wants to go forever and I don't know how to have the computer recognize that all selections have been made. You can check out what I have using the link below.
http://scratch.mit.edu/projects/45830498/
Edit: I now have it working, but I'm sure that there is a much better way to solve this problem. Please look at what I have and make suggestions.
http://scratch.mit.edu/projects/45830498/
Edit: I now have it working, but I'm sure that there is a much better way to solve this problem. Please look at what I have and make suggestions.
Last edited by runger (Jan. 31, 2015 22:02:41)
- Discussion Forums
- » Help with Scripts
-
» Lists and variables question