Boolean variables
- Started
- Last post
- 10 Responses
- DeIntegro
I need to understand why or if it is necessary to set the boolean variable to 'false', why not 'true'? confused...
and i've figured out that going with my intuition is pretty much always false...i need to think like a computer...still learning how that goes beyond following instructions...question is "which instructions to set, where? why?
// Boolean variable starts as false
boolean going = false;// Location of circle
int circleX = 0;
int circleY = 100;void setup() {
size(200,200);
smooth();
}
void draw() {
background(255);// Draw the circle
stroke(0);
fill(175);
ellipse(circleX,circleY,50,50);// Only move the circle when "going" is true
if (going) {
circleX = circleX + 1;
}
}// Set going to true when the mouse is pressed!
void mousePressed() {
going = true;
- dorf0
if you set it to true from the start, then the program will think that the button is pressed. In this case, it's set to false because the user needs to press the mouse button to start drawing the circles.
- DeIntegro0
simple enough...thanks...but i'm really bad at this more used to thinking with intuition and not logic!
- ********0
Why why why did I read this as Boolean vegetables? Shit I am losing it.
- DeIntegro0
my brain is vegetables right now been thinking about conditionals for 5 hours now! that's why boolean variables is posted! need to take a 2 hour break to digest...although i think i might like conditionals in the future!
- are you just reading from the processing website?dorf
- no...from a book. quick question though, this might be a dumb question as i feel pretty dumb right now:DeIntegro
- at the first 'if' statement 'going' is false? but when mouse is pressed going becomes true. so when the computer goes back to the boolean variable 'if' statement is now true, so circle moves, right?DeIntegro
- draw boolean variable is true in the 'if' statement, so circle moves again, right?DeIntegro
- NONEIS0
It's all about a condition, is the mouse down? set going to true and it animates, is the mouse up? set going to false and the animation stops – looks like all you are missing is a function / event combo for each mouse action..
- DeIntegro0
smh
- ********0
A boolean variable is really just a very small (two state) variable.
You could use other types of variable in it's place - but in situations where you're only checking for one of two states, using a different variable (data) type would be wasteful .. e.g. you'd be using more memory than you need to.
Maybe it would help to think of it as a bucket .. empty or full?
- sounds more like a switch - on or off.
bucket could be half full..... of shitAmicus - < true, that is half full of shit - the variable states translate to '0' (true) or 'not 0' (false), which is how you could possibly use another data type .. but you didn't really need the info; is prob unnecessarily confusing.********
- another data type .. but you didn't really need the info; is prob unnecessarily confusing.********
- GAH! false is 0, true is non-zero! Ignore me, I need coffee ..********
- sounds more like a switch - on or off.
- DeIntegro0
lukus i think the analogy of off or on is useful, maybe more than bucket...my real issue is knowing where to put what when...or program flow...i get some of the basic setup thus far in my studies it's been about 5 days of studying...but the critical parts sometimes escape me! agh! probably need more practice. right now i'm like a baby trying to ride a bicycle...definitely need training wheels!



