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.
Page Index Toggle Pages: 1
naming objects (Read 368 times)
naming objects
Apr 1st, 2008, 8:15pm
 
how do i create an object and name it so that i can reference it later without redrawing it?
Re: naming objects
Reply #1 - Apr 3rd, 2008, 6:54am
 
Code:

class MyThing{
int myNum = 3;
float myVal = 4;
}
MyThing c;
void setup(){
c = new MyThing();
}
void draw(){
//Now, I can draw the mything:
point(c.myNum,c.myVal); //Or something weird.
}


Your question is vague.

What I have outlined above is a very simple example of how to use objects. First define your own class, or use an existing one (like "String"). Then, "make" one with the keyword "new". You draw things in draw(), but you can specify what to draw! Just because you made an object doesn't mean it draws on its own. you have to make it draw! (the "point" call above draws a point according to c's values)

Hope this help.s
Re: naming objects
Reply #2 - Apr 4th, 2008, 6:56pm
 
@vaughn2 - the important thing to note about taifun's example is that he put the reference to the object variable (c) outside of any functions, at the top of his program. In setup it is defined, and now any function anywhere in the main program can access the object c.
Page Index Toggle Pages: 1