Skip to content

Keeping Things Together ๐Ÿงบ

Keep lots of things under one name: count them, pick one, and change them all at once


A Bunch of Colours ๐ŸŽจ

A bunch keeps many things together under one name. Here's a bunch of colours, used one at a time:

Canvas rainbow having width 400, length 200, fill "lightyellow"
bunch colors = "red", "orange", "gold", "green", "blue"
repeat colors.count times {
  draw circle at 70 * count, 100 having radius 30, fill colors[count]
}
  • colors.count is how many colours there are: 5.
  • colors[count] picks one: colors[1] is "red", colors[2] is "orange", and so on.

You can also write item 2 of colors instead of colors[2], and list instead of bunch. They mean the same.

The first thing is number 1, like count. (Some other languages start at 0. VeeLang starts at 1.)


Keep What a Loop Makes ๐ŸŽˆ

Put add to after a loop's }, and every shape the loop makes goes into a bunch:

Canvas party having width 400, length 300, fill "lavender"
repeat 6 times {
  draw circle at 55 * count, 200 having radius 22, fill "pink"
} add to balloons
balloons[2].fill = "gold"
balloons.last.fill = "skyblue"

Now balloons holds all six balloons, and you can pick any of them.


Change Them All at Once โœจ

Changing a bunch changes every shape in it, all at the same time:

Canvas party having width 400, length 300, fill "lavender"
repeat 6 times {
  draw circle at 55 * count, 250 having radius 22, fill "pink"
} add to balloons
move balloons by 0, -180 in 3 seconds
balloons.fill = "tomato" in 1 second

Every balloon floats up together. turn, grow, hide and show work on bunches too.


One at a Time ๐Ÿ‘†

repeat for each goes through a bunch one thing at a time. Here each balloon floats up after the one before it:

Canvas party having width 400, length 300, fill "lavender"
repeat 6 times {
  draw circle at 55 * count, 250 having radius 22, fill "pink"
} add to balloons
repeat for each b in balloons {
  move b by 0, -180 in 0.5 seconds
}

b is the balloon it's on: the first one, then the second, and so on.


Plant a Garden ๐ŸŒท

add to works after a when too: each click adds what it made. And when any runs when any shape in a bunch is clicked:

Canvas garden having width 400, length 300, fill "lightblue"
bunch flowers
draw rectangle ground at 0, 220 having width 400, length 80, fill "sienna"
when ground is clicked {
  draw circle at 40 + 45 * flowers.count, 190 having radius 18, fill "pink"
  draw circle at 40 + 45 * flowers.count, 190 having radius 6, fill "gold"
} add to flowers
when any f in flowers is clicked {
  grow f by 2 in 1 second
}

Click the ground to plant a flower, then click a flower to make it grow. Each flower is two circles, and they go into the bunch together, as one thing, so the whole flower grows.

bunch flowers at the top makes one bunch for all the clicks. (A bunch made inside a when or a repeat is a new one each time.)


Collect Them All ๐Ÿ’ฐ

when any โ€ฆ touches watches every shape in a bunch:

Canvas field having width 400, length 300, fill "lightgreen"
draw circle ball at 200, 270 having radius 15, fill "tomato"
score = 0
draw text points at 60, 25 having content "Score: " + score, size 18
repeat 8 times {
  draw circle at random 20 to 380, random 50 to 230 having radius 8, fill "gold"
} add to coins
when any c in coins touches ball {
  hide c
  remove c
  score = score + 1
  points.content = "Score: " + score
  if coins.count is 0 {
    points.content = "You got them all!"
  }
}
forever {
  if key leftarrow is down { move ball by -3, 0 }
  if key rightarrow is down { move ball by 3, 0 }
  if key uparrow is down { move ball by 0, -3 }
  if key downarrow is down { move ball by 0, 3 }
  wait 0.02 seconds
}

Click the drawing, then steer with the arrow keys. remove c takes the coin it touched out of the bunch. (A shape taken out stays on the drawing, so it's hidden too.) When coins.count is 0, every coin is collected.


Watch Out ๐Ÿ‘€

  • The first thing is [1], not [0].
  • One bunch holds one kind of thing: all numbers, all words or all shapes, say.
  • remove takes a thing out of a bunch, but a shape you take out stays on the drawing.
  • Something made of several shapes has no colour of its own. Put the shapes you want to colour in a bunch of their own: draw circle โ€ฆ add to petals.
  • To click any shape in a bunch, write when any f in flowers is clicked, not when flowers is clicked.

Challenge Time! ๐Ÿ†

  • ๐ŸŒŸ Challenge 1: Make a bunch of five sizes and draw a circle of each size.
  • ๐ŸŒŸ Challenge 2: Make a row of squares, then make them all twinkle by hiding and showing them in a forever.
  • ๐ŸŒŸ Challenge 3: In the garden, make each flower a different colour, using a bunch of colours and flowers.count.

What's Next? ๐Ÿš€

With bunches, your games can have as many coins, enemies and flowers as you like. Look up everything about them in the Bunches reference.