Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (kzhao, AndrewAMD, bigsmack, 7th_zorro), 869 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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 Offline OP
Member
NeoJones  Offline 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:

Code:
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 Offline
Senior Expert
3run  Offline
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!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Waiting for the end of a function [Re: 3run] #455883
11/02/15 12:51
11/02/15 12:51
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
You could also avoid the wait call in 'test' function and cut it in three: creator, loop content and remover. So the waiting function calls the creator before its loop, 'test' loop content as condition of the waiting function, and remover when breaking waiting funtion loop.

Code:
ENTITY *entBulletCreate ( VECTOR *vPos, VECTOR *vDir )
{
   ...
   ENTITY *entBullet = ent_create ( ...
   ...
   return entBullet;
}

var fnBulletMove ( ENTITY *ent )
{
   ...
   c_move ( ent, ...
   if ( HIT_TARGET )
      return 0;
   else
      return 1;
}

function entBulletRemove ( ENTITY *ent )
{
   ent_remove ( ent );
}

funtion start ()
{
   ENTITY *entBullet = entBulletCreate ( ...
   ...
   while ( entBulletMove ( entBullet ) )
   {
      ...
      wait(1);
   }
   ...
   entBulletRemove ( entBullet );
}


Re: Waiting for the end of a function [Re: txesmi] #455884
11/02/15 12:52
11/02/15 12:52
Joined: May 2008
Posts: 2,113
NRW/Germany
alibaba Offline
Expert
alibaba  Offline
Expert

Joined: May 2008
Posts: 2,113
NRW/Germany
Also look for "wait_for" in the manual


Professional Edition
A8.47.1
--------------------
http://www.yueklet.de
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 Offline OP
Member
NeoJones  Offline 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:

Code:
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 Offline
Senior Expert
Quad  Offline
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 Offline OP
Member
NeoJones  Offline OP
Member

Joined: Dec 2010
Posts: 224
NRW, Germany
Originally Posted By: Quad
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 Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Originally Posted By: Dragonfly
Mh I tried that but it doesnt work with a wait() in the "test"-function...

That's exactly what Quad was saying. wink He just gave you a heads up probably because your code example applies to that, not your real question:
Code:
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
Re: Waiting for the end of a function [Re: Superku] #455921
11/03/15 08:41
11/03/15 08:41
Joined: Dec 2010
Posts: 224
NRW, Germany
NeoJones Offline OP
Member
NeoJones  Offline OP
Member

Joined: Dec 2010
Posts: 224
NRW, Germany
Oh sorry. Then I understand it wrong. Thanks Superku laugh


Errors are the engine of progress.

Version: A8 Commercial
OS: Win 7 64bit
Models: Cinema 4D

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1