We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › boolean and if - beginner
Page Index Toggle Pages: 1
boolean and if - beginner (Read 876 times)
boolean and if - beginner
Feb 7th, 2010, 3:19pm
 
hi,

just try a little bit but i doesnt work...

Code:
boolean value = true;
  print(value);

void mousePressed() {
 if(value == false) {
  print(value);
 } else {
  print(value);
 }
}


why wont work this ? just want to change the status of value
thank u
Re: boolean and if - beginner
Reply #1 - Feb 7th, 2010, 4:41pm
 
it doesnt work because you dont do anything except printing the value...
so set it to false, or true before printing it in your mousePressed()
Re: boolean and if - beginner
Reply #2 - Feb 7th, 2010, 4:59pm
 
it just gives me some error messages...

i dont get it why its wrong.

i just define a boolean.
then check if its true false, and print the status.

Undecided
Re: boolean and if - beginner
Reply #3 - Feb 7th, 2010, 8:27pm
 
copy/pasting and running your code from above in processing gives the error
unexpected token: void
the way you use function print() here causes the error (function-calls should not be made from outside a function). if you put print(value) inside function setup for example, you should see the word true appear in the console. but you wont see any results happening when you click inside the sketch window that just opened. if you add function draw, your mouse actions will result in a feedback in your console as well.
Re: boolean and if - beginner
Reply #4 - Feb 8th, 2010, 2:06am
 
I think the issue is a little more complex: you can use print() in a simple 'static mode' sketch (i.e. one without setup and draw methods), but when any of these are included (or in fact mousePressed) you get the error.  I suspect the reason for this is the fact that the interpretor handles static sketches differently to those that include setup and draw (or other 'interactive' methods)...

Whilst 'static mode' is fine for very simple sketches to test basic functionality you're mostly going to be wanting things to happen, like registering mouse presses, and that requires a draw loop (mouse events are registered after each draw loop); which means including both setup and draw methods.  I'd suggest looking through the getting started section for clarification and some examples Wink
Re: boolean and if - beginner
Reply #5 - Feb 8th, 2010, 2:59am
 
Obviously you can change status with
Code:
value = true;
// or
value = false;


If you want to flip the status i.e. true>false  false>true then
Code:
value = !value; 

Page Index Toggle Pages: 1