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 › Simple syntax question
Page Index Toggle Pages: 1
Simple syntax question (Read 923 times)
Simple syntax question
Aug 20th, 2009, 2:31pm
 
Just coming over to proccesing from learning PHP and I wanted to know if there was a way to make this bit of code valid
--------------------------
void setup(){
size(200,200);
smooth();
background(0,0,0);
String x="ellipse";
x(100,100,20,20);

}
--------------------------

I just want to replace x with ellipse to call it as a function.
Re: Simple syntax question
Reply #1 - Aug 20th, 2009, 2:36pm
 
AFAIK, no.

But depending on what you want to achieve, there are maybe workarounds.
Re: Simple syntax question
Reply #2 - Aug 20th, 2009, 10:44pm
 
You can do that with reflection, but it is an overkill. As antiplastik said, there are better alternatives...
Re: Simple syntax question
Reply #3 - Aug 22nd, 2009, 1:14am
 
If you are only trying to make code writing more efficient, you can make a function called x:
Code:
void setup() {
 ...
 x(100,100,20,20);
 ...
}

void x(int x, int y, int w, int h) {
 ellipse(x,y,w,h);
}
Re: Simple syntax question
Reply #4 - Aug 23rd, 2009, 10:54am
 
NoahBuddy wrote on Aug 22nd, 2009, 1:14am:
If you are only trying to make code writing more efficient, ...


I wouldn't call that efficient though.
Re: Simple syntax question
Reply #5 - Aug 23rd, 2009, 11:51am
 
It saves some keystrokes, at the cost of obscurity...
I don't think that's the purpose of the OP, but we don't know the real goal...
Page Index Toggle Pages: 1