Skip to content

Remembering Things 🧠

Variables that change, and if to decide what to do


A Variable Is a Name for a Value 📦

Give a name a value with =, and use the name wherever you'd use the value:

Canvas paper having width 400, length 300
size = 40
draw circle at 200, 150 having radius size, fill "orange"

size = 40 makes a variable called size. You've seen number size = 40 before: that works too, and does the same thing.


Changing a Variable 🔁

Give it a new value the same way. The new value can use the old one:

Canvas paper having width 400, length 300
size = 20
draw circle at 100, 150 having radius size, fill "orange"
size = size + 20
draw circle at 250, 150 having radius size, fill "orange"

size = size + 20 means "take what size is now, add 20, and keep that". Each line sees the value size had when it was reached, so the two circles are different sizes.

A variable keeps the kind of value it started with. After size = 20, size = "big" is a mistake: size holds a number.


Remembering Between Clicks 👆

A variable changed when a shape is clicked keeps its new value, ready for the next click. Click the fan, and click it again. Each click makes it faster:

Canvas paper having width 400, length 300
draw rectangle fan at 150, 140 having width 100, length 20, fill "skyblue"
speed = 0
forever {
  turn fan by 90 * speed in 1 second
}
when fan is clicked {
  speed = speed + 1
}

The forever reads speed every time round, so it sees what the clicks did.


Keeping Score 🏅

Join the score to some words with +, and show it again after every click:

Canvas paper having width 400, length 300
score = 0
draw text label at 20, 40 having content "Score: " + score, size 28
draw circle coin at 200, 160 having radius 40, fill "gold"
when coin is clicked {
  score = score + 1
  label.content = "Score: " + score
}

True or False ✅❌

A variable can also hold true or false, for things that are either on or off. not swaps one for the other:

Canvas paper having width 400, length 300
draw circle lamp at 200, 150 having radius 40, fill "gray"
lit = false
when lamp is clicked {
  lit = not lit
  if lit {
    lamp.fill = "gold"
  }
  otherwise {
    lamp.fill = "gray"
  }
}
  • lit = not lit turns false into true, and true back into false.
  • if lit { } does what's inside only when lit is true. If it isn't, the lines in otherwise { } happen instead.

Checking Numbers 🔢

if can check numbers too. You can write the check in words, or with symbols:

Words Symbols True when
clicks is 3 clicks == 3 clicks is exactly 3
clicks is not 3 clicks != 3 clicks is anything but 3
clicks is more than 3 clicks > 3 clicks is 4 or more
clicks is less than 3 clicks < 3 clicks is 2 or less
clicks is at least 3 clicks >= 3 clicks is 3 or more
clicks is at most 3 clicks <= 3 clicks is 3 or less

This balloon pops after three clicks:

Canvas paper having width 400, length 300
draw circle balloon at 200, 150 having radius 30, fill "tomato"
clicks = 0
when balloon is clicked {
  clicks = clicks + 1
  grow balloon by 1.3 in 0.3 seconds
  if clicks is at least 3 {
    hide balloon in 0.2 seconds
  }
}

if works outside clicks too. There, it decides what the picture shows:

Canvas paper having width 400, length 300
repeat 5 times {
  if count % 2 == 0 {
    draw circle at 70 * count, 150 having radius 20, fill "gold"
  }
  otherwise {
    draw square at 70 * count - 20, 130 having size 40, fill "skyblue"
  }
}

count % 2 == 0 is true for 2 and 4, the even numbers, so they get circles.


Two Checks at Once 🔗

and is true when both checks are. or is true when at least one of them is:

Canvas paper having width 400, length 300
repeat 7 times {
  if count > 2 and count < 6 {
    draw circle at 50 * count, 100 having radius 15, fill "gold"
  }
  if count is 1 or count is 7 {
    draw circle at 50 * count, 200 having radius 15, fill "tomato"
  }
}

The gold circles are for 3, 4 and 5: bigger than 2 and smaller than 6. The red ones are for 1 or 7.

not is checked first, then and, then or. When you want something else, use brackets: not (lit or warm).


if or when? 🤔

  • when waits for something to happen: when lamp is clicked { }.
  • if checks something right now: if lit { }, if speed > 3 { }, if spin is playing { }.

Watch Out 👀

  • = gives a value: speed = 3. To check, use is or ==: if speed is 3 { }.
  • true, false, not, and and or are VeeLang's own words, so they can't be names.
  • A variable changed inside when ... is clicked has to be made at the top first, like speed = 0.

Challenge Time! 🏆

  • 🌟 Challenge 1: Make a circle that gets bigger each time you click it, but never bigger than radius 100.
  • 🌟 Challenge 2: Make a traffic light that goes red, then yellow, then green, one colour per click.
  • 🌟 Challenge 3: Make a fan that speeds up with each click, and stops after five clicks.

What's Next? 🚀

Your drawings can remember things now. Mix variables, if, clicks and moving to make a game with a score! ✨