FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   really beginning beginner
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: really beginning beginner  (Read 683 times)
sparky_monkey


really beginning beginner
« on: Jan 1st, 2003, 6:59pm »

uh....so can I return a value from a method....and if so how would it be done...?
 
I am attempting to use a global variable that will be sometimes passed to a method, messed with by the method and then returned to the main loop....
 
does this make sense?
 
aargh....my programming skills are rusty!
 
Glen Murphy

WWW Email
Re: really beginning beginner
« Reply #1 on: Jan 1st, 2003, 8:05pm »

To return something from a method, the method must be of the same type as what it returns.
 
For example:
 
void doSomething() {whee;} returns nothing
 
int doSomething2() {whee; return 1;} returns an INT
 
String doSomething3() {whee; return "bucket";} returns a String
 
In your case, you could have something like so:
 
Code:

int GLOBALVARIABLE1 = 1
 
int addertron() {
  return GLOBALVARIABLE += 2;
  }

This really isn't the proper way to do it (for various reasons). So if you feel like it, you could make it a little 'better', and do it as follows:
 
Code:

int GLOBVAR1 = 1;
 
int addertron(int g) {
  return g += 2;
  }
 
GLOBVAR1 = addertron(GLOBVAR1);

If this doesn't make any sense, it's partially because I haven't slept yet, and I am therefore nonsensical. whee.
 
sparky_monkey


Re: really beginning beginner
« Reply #2 on: Jan 8th, 2003, 8:28am »

hey... thanks a lot....wow....and so quickly!
 
I think I actually got it....
 
of course it's not the answer I wanted for what I am trying to do, but that's okay.
 
 
Pages: 1 

« Previous topic | Next topic »