We're gonna pause for a moment, it's not really a pause but I wanna,
we're on this train on
fundamentals and computation. We're just plowing through all these concepts
we'll stop for a moment and just talk about
a function in Processing that you might not see
in a lot of examples but you will inevitably wanna use
all the time: 'println'
or 'print line' and it gets some argument here
here's the thing, you know
stuff is gonna go wrong all the time. you're gonna write some code,
you're gonna run it, it will have an error, you gonna fix the error, you're gonna run it but it's not gonna do what you expected it to do
you're gonna feel sad and stressed out, you know you'll get some tea, you'll relax, you'll ask a friend
things will eventually be okay but there is a process there about figuring out
and this is really what I wanna say,
is that it's very different this scenario where your code does not run
and you get an error
because you got a typo and your code runs, there are no errors
but it doesn't do what you imagine it to do, there's lots and lotsa
debugging, or the
debugging techniques, to get the bugs out of your program
there's a lot of strategies for doing that hopefully we'll see as I make these
videos and
you know there's any good thing about not rehearsing or planning any of these videos, hopefully
I will make mistakes as of
kind of doing examples they will see some debugging during the course of these videos
but
we haven't got very far yet so we're not really ready for all the tools we
might have but
this is a tool for figuring out when something goes wrong
that you might wanna have at your disposal right now.
so let's look at what this does: the first thing that I should just say
if you have, you can put anything in here: I can write,
in quotes, the word 'hello' and this will print
'hello' to Processing's message console.
Where is the message console? Right, there's like the tool bar up here
you have some code you've written
there's a little, there's a place down here where those errors
appear, right? Where messages are spit out if something goes wrong with your program
you can print stuff to down there yourself, it's not part of the
application window
but it's extra information as the programs running, so you could put
a string of characters in there, you could put a number in there
but you could also do something like this:
'println circleX' and you will see
the value of circle X printed out down there. Why would this be useful?
So let's go over here look at the program. This is what we've been
working on.
it's a program that draws a circle on the screen with an initial location, maybe
that circle's location changes
and if we run we can look at it and see there's no circle, what's going on?
I have a variable called circleX, I am drawing the ellipse at circleX
and I have this line of code but I don't see the circle.
So obviously this is a canned scenario that I've created
perhaps you can just look at the scenario and already see what the problem is
but let's pretend that you can't
so one strategy we have is to say
println (circleX) and when I run this program
now we can see down here, look the message console, all these values are
printing out
this is the current value of circleX, now we look at this and we know instantly
okay I know why I'm not seeing it on the screen: the value of circleX is a
really high negative number, there's no negative pixels on the screen,
Processing is like pretending to draw
it way off so that's why we don't see it. that's what broken
okay so how now like his a clue at least two figuring out what the problem is
now I could guess like well maybe I should comment out this line of code
and run it again, what's the value of circleX?
oh, it's 0 all the time, that make sense, that was its
initial value
and so this line of code but somehow we're making it negative
Oh, of course, I'm adding a random number between
-2 and 0 so I'm never incrementing it by a positive number
circleX starts at 0 and only ever gets to be negative. Ah, what I meant to do was
say not between -2 and 0 but
between 0 and 2 and now I run my program, oh, it's on the screen
it's moving and I see that the value of circleX is now positive
I mean this is a really quick video just to show you that
this is a tool that's available to you
you might kinda practice with it, you can do interesting things like
you can actually, say, put a string of characters in here
with the plus sign, so if i write the code like this
this isn't 'adding' but in the case of print line, we're going to see more about his
when we learn about strings later,
we want a print line circleX, colon, and then the value
circleX, so, oops, so if I run it
we can see that's what's being printed out now down there
circleX, colon,and this is useful if you wanna print
multiple values out, and you need to label them, and you can go all sorts of crazy with this!
and I would ...
stop recording and just make lots of pretty, like elaborate,
print line statements on my own
cause I enjoy doing that but, uhm, I don't think you need to worry too much about this
most the stuff you're doing right now you going to be able to fix and solve
through trial and error, kind of creating these simply programs.
this is just a quick little video to show you about 'println'.
and hopefully that was useful!