|
Waiting for the end of a function
#455881
11/02/15 11:31
11/02/15 11:31
|
Joined: Dec 2010
Posts: 224 NRW, Germany
NeoJones
OP
Member
|
OP
Member
Joined: Dec 2010
Posts: 224
NRW, Germany
|
Hey guys, is there a way to waiting for the returned value of a function? For example:
function test()
{
//some code here
...
return 1;
}
function start()
{
while(test() == 0) //how can i wait for the end of the "test" function?
{
wait(1);
}
}
Can someone help? Regards, DF
Errors are the engine of progress.
Version: A8 Commercial OS: Win 7 64bit Models: Cinema 4D
|
|
|
Re: Waiting for the end of a function
[Re: NeoJones]
#455882
11/02/15 12:20
11/02/15 12:20
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
Hey! I see two ways to do this: First one - use proc_status. Second one - use global variable, which will change to ONE at the beggining of that 'test' function, and will be reset back to ZERO when you rich the end of the function (after f.e. a loop). So you'll be able to check, if that variable is equal to ONE, then wait for that function.. Just a dirty but well working idea. Best regards!
|
|
|
Re: Waiting for the end of a function
[Re: 3run]
#455885
11/02/15 12:53
11/02/15 12:53
|
Joined: Dec 2010
Posts: 224 NRW, Germany
NeoJones
OP
Member
|
OP
Member
Joined: Dec 2010
Posts: 224
NRW, Germany
|
Many thanks 3run. proc_status was the key. With this I found another solution (in the manual) and it works for me:
function foo()
{
int i;
for (i=0; i<100; i++) { wait(1); }
}
...
foo();
wait_for(foo); // wait until foo is terminated
Best regards! Edit: Oh I wrote and dont saw the other answers, sorry xD Thanks for all answers!
Last edited by Dragonfly; 11/02/15 12:55.
Errors are the engine of progress.
Version: A8 Commercial OS: Win 7 64bit Models: Cinema 4D
|
|
|
Re: Waiting for the end of a function
[Re: NeoJones]
#455888
11/02/15 13:48
11/02/15 13:48
|
Joined: Oct 2007
Posts: 5,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
|
unless you have a wait() somewhere in that test function, it already waits for the return value.
3333333333
|
|
|
Re: Waiting for the end of a function
[Re: Quad]
#455889
11/02/15 14:06
11/02/15 14:06
|
Joined: Dec 2010
Posts: 224 NRW, Germany
NeoJones
OP
Member
|
OP
Member
Joined: Dec 2010
Posts: 224
NRW, Germany
|
unless you have a wait() somewhere in that test function, it already waits for the return value. Mh I tried that but it doesnt work with a wait() in the "test"-function...
Errors are the engine of progress.
Version: A8 Commercial OS: Win 7 64bit Models: Cinema 4D
|
|
|
Re: Waiting for the end of a function
[Re: NeoJones]
#455894
11/02/15 15:27
11/02/15 15:27
|
Joined: Sep 2003
Posts: 6,861 Kiel (Germany)
Superku
Senior Expert
|
Senior Expert
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
|
Mh I tried that but it doesnt work with a wait() in the "test"-function... That's exactly what Quad was saying. He just gave you a heads up probably because your code example applies to that, not your real question:
function test()
{
//some code here
...
[SO NO WAIT HERE OR WHAT? OTHERWISE YOU CAN'T RETURN STUFF ANYWAY]
return 1;
}
function start()
{
while(test() == 0) //how can i wait for the end of the "test" function?
{
wait(1);
}
}
"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual Check out my new game: Pogostuck: Rage With Your Friends
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|