Okay we're getting close now, we're getting close.
There's just this moment, I can see it, there's two bubbles, we're soon
going to have a thousand bubbles, it's very exciting.
So we're, what do we have so far? We know how to declare,
this list of numbers; integers.
We were going to look at an example that used a list of integers,
and maybe that's a bit of a mistake, and I'll try to fit that in again
somewhere. But you know, think about that, how might you do that?
But what I want to move straight to is saying, "Let's apply this thinking
to these bubbles." And instead of having separate bubble object variables, lets
have a single list of bubble objects.
So if we look at this syntax, the first thing we have is the type of the array.
Now we're going to have a type "Bubble" the object "Bubble".
We need to make sure it's going to be an array, great we need to give our array a
name, let's call it "Bubbles". The wire's a good joke, just thinking of
the wire, because of the name, "Bubbles", but you didn't really need to know that.
I think I should make some magic way, where I could just like, edit out
unnecessary thoughts.
Okay um... and then we need to say how many bubbles are we going to have in our
array; we're going to have two. We're not getting very ambitious here, we're getting
very very basic simple, we're going to have just two, um, I also by the way
noticed, there's this little monitor that I look at, which is slightly above the
camera, I feel like I'm always looking above the camera. But if I look this way,
I'm looking right at the camera, right at you.
Okay, so let's try to apply this here. So, what's going on? Look, bubble, let's
close this, Bubble b1; Bubble b2; first of all, you know
we really should've done this, just to get us in that frame of reference, of
thinking of counting from zero, from the rest of your life, you should
just count from zero from now on, always start at zero.
Okay, uh... what I want to do is instead of having two separate variables, I want
to have an array, called "bubbles", it's going to be of type "Bubble", it's
got the brackets, which means it's an array, we name this "bubbles",
and it has two bubbles in it. There's a lot of bubble everywhere but you know,
this is what's happening to us right now.
So we can get rid of this. Now, instead of initializing a single bubble...
we can now refer to the bubbles by their index value, we can say, "Bubbles index 0
make a new bubble." "Bubbles index 1 make a new bubble."
So, its like we had two separate variables but both of those variables exist as spots
in a list. You can imagine this list with two spots in it, and there's one bubble
here, and another bubble there. Um, okay, so what do we do now?
We need to take this idea and say,
bubbles[0].ascend(); bubbles[0].display(); bubbles[0].top();
bubbles[1].ascend(); bubbles[1].display(); bubbles[1].top();
There we go, we have the identical program, just what we had before.
Okay, so you know what? I'm just going with this, I'm experimenting with shorter
videos, this has only been two, two and a half minutes (3 mins 17 seconds actually),
but let's actually stop here, so this is a good, obviously this is a huge problem
right? We've kind of done nothing to, to get towards our goal of having a thousand
bubbles right? Yes, we've put it in a list but we still have individual lines of code
for each bubble, we have to say, bubbles[0].all the functions;
bubbles[1].all the functions;
then if we had a thousand, two and three and four all the way up to 999.
So, we're on the way there but we're missing an important step, and that
important step is going to be using a loop, and that's we're going to be doing in the
next video. But, let's take a moment to pause here and what I would say to you as
an exercise is go find something where you had an object and try to make an array of
those objects. Try to make multiple objects and use the array, don't just
and refer to which object by its index value.
You can do interesting things like, um, I could say, if I wanted to that this second
one shouldn't bother to ascend, only the first one [needs to ascend].
You can see the second one, now doesn't have that function called on it, so it's
just laying there at the bottom, so that's what I would say to you, take your object
that you made make an array of them and try to see how that works.
Subtitles by the Amara.org community