Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (ozgur, EternallyCurious, howardR, 1 invisible), 623 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
do while problem #465817
05/14/17 08:29
05/14/17 08:29
Joined: Dec 2010
Posts: 224
NRW, Germany
NeoJones Offline OP
Member
NeoJones  Offline OP
Member

Joined: Dec 2010
Posts: 224
NRW, Germany
Hey guys,
i would like to know, how I can solve that problem.
I need a result of a function, that contains a while loop for example:
Code:
function sec_func(var param1)
{
	var i = 0;
        var new_value = 0;

	while(i < 1000)
	{
		i++;
		new_value += getValue(i);
	}
	return new_value;
}

function first_func()
{
        var my_value = 0;	
        while(1)
	{
		my_value = sec_func(50); //no correct result
		wait(1);
	}
}



The above code is just only an example.
My problem is, that I dont get the correct result of sec_func, because the function need to much time to give me a correct result. How can I manage that?

Regards, NJ


Errors are the engine of progress.

Version: A8 Commercial
OS: Win 7 64bit
Models: Cinema 4D
Re: do while problem [Re: NeoJones] #465818
05/14/17 09:43
05/14/17 09:43
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
Budapest
What do you want finally?
Seems to me there is at least one problem with your code: sec_func doesn't use the param1 variable.
There may be others.

Re: do while problem [Re: Aku_Aku] #465820
05/14/17 09:55
05/14/17 09:55
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline
Serious User
Reconnoiter  Offline
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
For readability I would replace the while loop with a for loop, cause there is another strange thing I notice; you do i++ even before you use the 'i' variable in the array, so getValue[0] never gets used (also use square brackets for arrays not ()).

Last edited by Reconnoiter; 05/14/17 09:56.
Re: do while problem [Re: Aku_Aku] #465822
05/14/17 10:07
05/14/17 10:07
Joined: Dec 2010
Posts: 224
NRW, Germany
NeoJones Offline OP
Member
NeoJones  Offline OP
Member

Joined: Dec 2010
Posts: 224
NRW, Germany
@Aku_Aku: Oh sorry, yes right. param1 is not used xD This is only an example. I dont need this code for something. Iam very interested, how I can manage that, if I need a result of a function, that contains a while loop and need more time to finish.
The problem is, that the script dont waiting for the other functions.
My only idea is to make a global variable, save the result of the second function in it and wait in the first function for a value.
Or can I use wait_for for that? my_value = sec_func(50); must wait for the sec_func to complete. You know what i mean?

@Reconnoiter: Yes of course. Thats only an example. This -> my_value = sec_func(50); is important for me. The script should be wait for a result of a second function. It gives me an incorrect result, cause the loop need more time to run...

Oh i hope you understand grin Sorry for my bad english xD


Last edited by NeoJones; 05/14/17 10:11.

Errors are the engine of progress.

Version: A8 Commercial
OS: Win 7 64bit
Models: Cinema 4D
Re: do while problem [Re: NeoJones] #465823
05/14/17 10:34
05/14/17 10:34
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline
Serious User
Reconnoiter  Offline
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Ah okay. Anyway you probably use/used a wait() somewhere in your original 'sec_func' before returning the value. Otherwise is should work.

Re: do while problem [Re: Reconnoiter] #465824
05/14/17 10:58
05/14/17 10:58
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: Reconnoiter
Ah okay. Anyway you probably use/used a wait() somewhere in your original 'sec_func' before returning the value. Otherwise is should work.


Yes i tried that but the manual says:
Quote:
A function that contains a wait loop can not return a parameter, because wait() already returns to the calling function before the final return statement is excecuted.
And thats my problem. Thats why i think about a workaround.

Last edited by NeoJones; 05/14/17 11:00.

Errors are the engine of progress.

Version: A8 Commercial
OS: Win 7 64bit
Models: Cinema 4D
Re: do while problem [Re: NeoJones] #465825
05/14/17 11:41
05/14/17 11:41
Joined: Oct 2008
Posts: 681
Germany
Ayumi Offline
User
Ayumi  Offline
User

Joined: Oct 2008
Posts: 681
Germany
Just put wait(1) in the first while or use a for loop, because he jump out...with wait(1) the function is waiting for second while. I have had the same problem with count alpha from Panel.

Re: do while problem [Re: Ayumi] #465826
05/14/17 11:48
05/14/17 11:48
Joined: Dec 2010
Posts: 224
NRW, Germany
NeoJones Offline OP
Member
NeoJones  Offline OP
Member

Joined: Dec 2010
Posts: 224
NRW, Germany
Okay, thanks laugh


Errors are the engine of progress.

Version: A8 Commercial
OS: Win 7 64bit
Models: Cinema 4D
Re: do while problem [Re: NeoJones] #465827
05/14/17 14:55
05/14/17 14:55
Joined: Sep 2009
Posts: 993
Budapest
Aku_Aku Offline
User
Aku_Aku  Offline
User

Joined: Sep 2009
Posts: 993
Budapest
If you want to wait for finishing of a function you should do this way:
Code:
function first_func()
{
        var my_value = 0;	
        while(1)
	{
		my_value = sec_func(50); //no correct result
		wait_for(sec_func);
		wait(1);
	}
}


In hope i understood you.

Re: do while problem [Re: Aku_Aku] #465832
05/14/17 18:21
05/14/17 18:21
Joined: Dec 2010
Posts: 224
NRW, Germany
NeoJones Offline OP
Member
NeoJones  Offline OP
Member

Joined: Dec 2010
Posts: 224
NRW, Germany
Thanks 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