Or a function, certain functions do calculations and.
Can give you back numbers, or other values.
Up to now, the functions we've seen just do stuff like drawing.
But sometimes we have a function like random, a very useful function, which
generates a random number. So this call is going to give us a random
number between zero and 100. But he's going to set posX to be equal to
that random number. So after that posX is a random value.
And we'll see in the main lecture how we can use a number of these functions to do
calculations and then give us back a value that we put in the variable.
So we're giving numbers to, this random function, we're giving it zero and a 100.
That controls How it works. Basically, for say, 0 and 100, the
random, it will give us a number between 0 and 100.
If I say 0 and 10, it'll give us a number between 0 and 10, and then it gives us
back a number if you present posX to there.
Some functions return And return strings, texts, Boolean variable values, images,
it can return any kind of type, but something that we, can be put in a
variable. We can also do calculations and put the
results in a variable. So we can take a value, which in this
case. It is another there.
For mouseX. MouseX is a variable which represents the
position of the mouse. The X position of the mouse.
And we add something to it. We add 1.
That gives us a new number. Whatever mouse X is plus 1 set for mouse
X. It's 100.
It's 101 If you can do basic math. And we take that value and put it in
posX. .
and we can do something else. We can take the value and change it based
on it's own old value. So we can take posX, make it equal to.
Itself but the old value of posX plus 1. So if posX is 30, we add 1 to 31 and set
posX to that. That's a way of changing a variable as we
use it. in in future lessons we'll see how we can
use that to animate things. By every time changing the value of the
variable, if that position, variable is a position or something similar, we can
make things move around. This is such a common thing to do,
there's this little shorthand for it. PosX plus equals one means posX equals
posX plus 1. It means exactly the same thing.
It's a way of adding a value to itself. posX plus, plus is an even shorter
shorthand when the, you know the value of adding is 1.
posX plus, plus just means add one. PosX.
PosX plus equals means add a number to it.