Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » looping through a list
- angeltra24
- New to Scratch
8 posts
looping through a list
Hi
I do have another forum post but i am getting more confused with the responses so i will try to explain, maybe easier.
I am creating a simon says games as part of my assignment
most of the script cant be edited except to scripts with “when i receive” hat blocks
the first hat block picks a random number that is associated with a colour and place it in a list,called colours
then it, puts them into another list called “sequence” list in a random order.
the second hat block “when i receive” then has to loop through the items in the 2nd list in order and broadcast them to the relevant sprites.
can i do that lol nope been on it for 3 days now and losing the will to live.
please see jpeg attached. http://imageshack.com/a/img823/2347/h6e6.jpg
I do have another forum post but i am getting more confused with the responses so i will try to explain, maybe easier.
I am creating a simon says games as part of my assignment
most of the script cant be edited except to scripts with “when i receive” hat blocks
the first hat block picks a random number that is associated with a colour and place it in a list,called colours
then it, puts them into another list called “sequence” list in a random order.
the second hat block “when i receive” then has to loop through the items in the 2nd list in order and broadcast them to the relevant sprites.
can i do that lol nope been on it for 3 days now and losing the will to live.
please see jpeg attached. http://imageshack.com/a/img823/2347/h6e6.jpg
- Fjpackard
- Scratcher
32 posts
looping through a list
To loop through a list, try something like this:
Then each time you loop you can do something with the variable currentItem.
Hope this helps!
Cheers,
Fjpackard.
when green flag clicked
set [num v] to [1]
repeat (length of [list v])
set [currentItem v] to (item (num v) of [list v])
change [num v] by (1)
end
Then each time you loop you can do something with the variable currentItem.
Hope this helps!
Cheers,
Fjpackard.
- drmcw
- Scratcher
1000+ posts
looping through a list
In create new sequence what is
Your play sequence just seems plain wrong. Try
change [colourPosition v] by (COLOURS)supposed to do? I think its deleteable.
Your play sequence just seems plain wrong. Try
when I receive [play sequence v]
set [index v] to [1]
repeat (length of [sequenceList v])
if <(item (index) of [sequenceList v]) = [green]> then
set [colourValue v] to [green]
broadcast [playWedge v] and wait
else
... // the other colour tests here
end
change [index v] by (1)
end
Last edited by drmcw (Jan. 14, 2014 09:29:42)
- mr_Sav
- New to Scratch
1 post
looping through a list
Superb superb thanks guys xx
Hi Angeltra - I am stumped on the same 3c question - could you provide any assistance it is driving me mad! Thanks
- gourls
- New to Scratch
17 posts
looping through a list
guys did yous ever complete this? I am stuck on the same parts as you were and my assignment has to be in by tuesday please help
- HueHue7
- New to Scratch
1 post
looping through a list
-
Last edited by HueHue7 (March 28, 2019 15:03:22)
- Discussion Forums
- » Help with Scripts
- » looping through a list