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 › Using void inside void
Page Index Toggle Pages: 1
Using void inside void (Read 1038 times)
Using void inside void
Aug 17th, 2005, 6:16pm
 
I don't know if this is possible:

Code:


void core(void a)
{
for(int i=0;i<10;i++)
{
a;
}
}



I could use [switch]... but can I use [void A(void B)]?

Thanks.
owd.
Re: Using void inside void
Reply #1 - Aug 17th, 2005, 7:36pm
 
meaning that you want to pass the method to be called to the method "core"?

the short answer is that you can't really do it, and should just use an if() statement. this is generally recommended.

the longer answer is that you can, but it requires either using "reflection", or making an "interface" or class that has a particular method, and then subclasses for each version of that method. the latter is discussed in older posts on the forum (you might try the old alpha board if a search doesn't turn anything up). there's also info in the java documentation (the java tutorial on sun's site might help) about both.
Re: Using void inside void
Reply #2 - Aug 17th, 2005, 8:48pm
 
fry wrote on Aug 17th, 2005, 7:36pm:
meaning that you want to pass the method to be called to the method "core"


Code:

void setup()
{
size(300,300);
background(255);
if(random(1000)<700)
{
A(C());
}else{
A(D());
}
}

void A(void B()) // processing says no,no,no
{
for(i=0;i<10;i++) // for example
{
B();
}
}

void C()
{
stroke(50);
ellipse(25,25,10,10); // for example
}

void D()
{
stroke(0);
point(100,100) // for example
}


Sorry, I'm another newbie.

Anyway I will search here...
Thanks, thanks and re-thanks, and thanks another time for your time, patience and work, Fry.

Nacho - owd.
Re: Using void inside void
Reply #3 - Aug 19th, 2005, 5:01pm
 
I think Nacho means if it is possible to pass a function as an argument of another function.

But I can't help you because I don't know the answer.

Maybe better off using "switch" like you said.
Re: Using void inside void
Reply #4 - Aug 20th, 2005, 12:52pm
 
That's exactly (void as argument) Ricard. I don't know Java, but I've found:

Code:


public static Function A(final Function B, final Function C)
{
return new Function()
{
public double valueAt(double _x) {
return B.valueAt(_x)+C.valueAt(_x);
};
};
}



But with Processing syntax.
It was simply a curiosity (too complex for me).
Regards.
Page Index Toggle Pages: 1