Gamestudio Links
Zorro Links
Newest Posts
zorro license, IB connection
by miwok. 12/06/23 16:32
Newbie Questions
by fairtrader. 12/06/23 11:29
Zorro Trader GPT
by TipmyPip. 12/04/23 11:34
Square root rule
by Smallz. 12/02/23 09:15
RTest not found error
by TipmyPip. 12/01/23 21:43
neural function for Python to [Train]
by TipmyPip. 12/01/23 14:47
Xor Memory Problem.
by TipmyPip. 11/28/23 14:23
Training with command line parameters
by TipmyPip. 11/26/23 08:42
AUM Magazine
Latest Screens
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Who's Online Now
6 registered members (miwok, AndrewAMD, TipmyPip, 3run, Quad, 1 invisible), 645 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
fairtrader, hus, Vurtis, Harry5, KelvinC
19019 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
wait_for #259015
04/03/09 13:39
04/03/09 13:39
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
I need a function a to wait until another function b (that a has called) has finished running.
I believe I cannot use wait_for though, because many instances of b may be running at the same time.
Is there a nice way to do this?

here's what wait_for does:
Code:
myfunction(myparameter);  // call a function with many wait()s (one instance only)
wait_for(myfunction);     // wait until myfunction is finished (lite-C only)


Last edited by Germanunkol; 04/03/09 13:44.

~"I never let school interfere with my education"~
-Mark Twain
Re: wait_for [Re: Germanunkol] #259018
04/03/09 13:53
04/03/09 13:53
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
i use something like
Code:
void LoadFromFile(STRING* str)
{
****
bLoadedFromFile=1;
}

function main()
{
***
	LoadFromFile("lev2.lvl");
	
	while (bLoadedFromFile==0) {wait(1); }
	bLoadedFromFile = 0;
***
}



1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: wait_for [Re: Germanunkol] #259025
04/03/09 14:11
04/03/09 14:11
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Sounds right to me.

Can you post the existing function A and function B ? (even an approximation)
If I can see what they so I may be able to figure a work-around.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: wait_for [Re: EvilSOB] #259029
04/03/09 14:29
04/03/09 14:29
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
//Can you post the existing function A and function B ? (even an approximation)

is it for me or Germanunkol? smile


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: wait_for [Re: VeT] #259031
04/03/09 14:33
04/03/09 14:33
Joined: Aug 2008
Posts: 2,838
take me down to the paradise c...
Cowabanga Offline
Expert
Cowabanga  Offline
Expert

Joined: Aug 2008
Posts: 2,838
take me down to the paradise c...
Quote:
[Re: Germanunkol]


Re: wait_for [Re: Cowabanga] #259032
04/03/09 14:35
04/03/09 14:35
Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
VeT Offline

Serious User
VeT  Offline

Serious User

Joined: Aug 2004
Posts: 1,345
Kyiv, Ukraine
i almost never look there ^^


1st prize: Lite-C and Newton 2.17 by Vasilenko Vitaliy

Newton2 videos: http://tinyurl.com/NewtonVideos
LiteC+Newton2 discussion: http://tinyurl.com/NewtonWrapperDiscussion
Latest LiteC+Newton2 version(v23, from 29.10.2009): http://depositfiles.com/files/ae1l0tpro
Re: wait_for [Re: VeT] #259078
04/03/09 18:17
04/03/09 18:17
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
VeT, i've used similar code before. The Problem is that I want to call the function mutliple times at once, so as soon as one instance is done running, all calling functions would continue.

EvilSob, I've not coded the function yet, but here was a test i did to this subject.

This is actually using Vet's code as well, but doesn't work at all. (it should take 500 frames before it beeps, right? well, it doesn't. you can try it out...)

Code:
#include <acknex.h>
#include <default.c>

FONT* fallbackFont = "Arial#12b"; // truetype font 


int lol= 0;
int lol2= 0;

PANEL* testPAN =
{
	pos_y = 150;
	digits = 0,0,10.4,fallbackFont,1,lol;
	digits = 0,12,4,fallbackFont,1,lol2;
	flags = SHOW;
}

int theNUMBER()
{
	int thenumber = 0;
	
	while(thenumber < 5000)
	{
		thenumber += 1;
		wait(1);
	}
		return(thenumber);
}

void main()
{
	fps_max = 10;
	wait(10);

	lol = theNUMBER();
	while(lol == 0){wait(1);}
	beep();
	lol2 = 10;
}


Last edited by Germanunkol; 04/03/09 18:18.

~"I never let school interfere with my education"~
-Mark Twain
Re: wait_for [Re: Germanunkol] #259095
04/03/09 20:49
04/03/09 20:49
Joined: Jul 2008
Posts: 170
Germany, near Mainz
Nicotin Offline
Member
Nicotin  Offline
Member

Joined: Jul 2008
Posts: 170
Germany, near Mainz
I didn't tested it. But you could use an array and proc status... like

Code:
var running[100];

function multiple_function(index)
{
 beep();
running[index] = 1;
}


function main()
{
 var function_number;
 multiple_function(function_number);
 while(running[function_number] == 0) {wait(1);}
 sys_exit();
  
}



I hope it is at least abit you were asking for? xD



Re: wait_for [Re: Nicotin] #259109
04/03/09 22:10
04/03/09 22:10
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Ive just put this together, and basic testing gives it the OK.
It may do the job for you if FunctionA noticing the functionB end-time is not too critical.
AND you can see the door is open to returning MULTIPLE values/types per instance.
I think there is enough documentation to see how to use it. Otherwise just ask...
Code:
var ID_Done=0, ID_Value=0;


void	FunctionB(var ID, var any_other_parameters)
{
	//normal function coding
	var Value_to_return = random(1000);
	/////////////////////////////////////////////////////////////////////////
	////completed, set completion flag.
	while(ID_Done)    wait(1);		//wait till ID_Done is unused
	ID_Done = ID;			//set ID_Done to ID of this instance
	ID_Value = Value_to_return;		//set return value
	/////////////////////////////////////////////////////////////////////////
	////untested optional "timeout" safety mechanism in case FunctionA stopped
	var t; for(t=0; t<100; t++)  { wait(1);  if(ID_Done!=ID) break; }
	if(ID_Done==ID)   ID_Done = 0;  //FunctionA not responding 
	/////////////////////////////////////////////////////////////////////////
}


function FunctionA()
{
	//normal function coding
	var ReturnFromB = 0;
	/////////////////////////////////////////////////////////////////////////
	//call FunctionB and wait for it to complete
	var ID = random(100000);		//generate unique instance number
	FunctionB(ID, any_other_parameters);	//call FunctionB
	while(ID_Done!=ID)   wait(1);	//Wait for instance to flag completion
	ReturnFromB = ID_Value;		//get its return value
	ID_Done = 0;			//release ID_Done for other instances to use
	/////////////////////////////////////////////////////////////////////////


	/////////////////////////////////////////////////////////////////////////
	//Untested Alternate version with "timeout" safety mechanism
	//call FunctionB and wait a set period of time for it to complete
	var ID = random(100000);		//generate unique instance number
	FunctionB(ID, any_other_parameters);	//call FunctionB
	var t; for(t=0; t<100; t++) { wait(1);  if(ID_Done==ID)  break;  } 
	if(ID_Done==ID)	{   ReturnFromB = ID_Value;	ID_Done = 0;	}
	/////////////////////////////////////////////////////////////////////////
}


Last edited by EvilSOB; 04/04/09 13:48. Reason: added Timeout safetys

"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: wait_for [Re: EvilSOB] #259324
04/05/09 13:58
04/05/09 13:58
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
Okay... both methods from the two of you pass along an ID to the called function. I think I'll try it with that method. thanks a lot smile

Micha


~"I never let school interfere with my education"~
-Mark Twain
Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

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