how do I tell the program to use a function only every second

Posted By: elevationmind

how do I tell the program to use a function only every second - 01/19/13 18:47

Hi,

I want to save the postition of the player every second of the game into a txt file. This works when I use the function save(); in my main while(1) loop.

But it saves the postition every 20th or so of a second - much to much data for me.

How can I say "use save(); only every 1/2 sec"?

Thx in advance!
Posted By: Uhrwerk

Re: how do I tell the program to use a function only every second - 01/19/13 19:09

By using wait with negative values.
Code:
wait(-10); // waits 10 seconds


http://www.conitec.net/beta/acrt-wait.htm
Posted By: elevationmind

Re: how do I tell the program to use a function only every second - 01/19/13 19:13

I know and tried that, but it doesn't help me because I don't want the program to wait ten seconds - I want something to happen every x seconds. How do I do that?
Posted By: MasterQ32

Re: how do I tell the program to use a function only every second - 01/19/13 20:55

while(1)
{
error("dafuq, why does this even work?");
wait(-1);
}
Posted By: Kartoffel

Re: how do I tell the program to use a function only every second - 01/19/13 21:41

Maybe you want to run a save-loop run in a seperate function:

Code:
void SaveLoop(var wait_time)
{
	while(1)
	{
		save();
		wait(-wait_time);
	}
}



f.e. call SaveLoop(2); once and save(); gets called every 2 seconds without affecting the rest of your code.
Posted By: Uhrwerk

Re: how do I tell the program to use a function only every second - 01/20/13 00:57

Originally Posted By: elevationmind
I know and tried that, but it doesn't help me because I don't want the program to wait ten seconds - I want something to happen every x seconds. How do I do that?

Do the tutorials. Seriously. http://tutorial.3dgamestudio.net/
Posted By: elevationmind

Re: how do I tell the program to use a function only every second - 01/20/13 11:20

Originally Posted By: Kartoffel
Maybe you want to run a save-loop run in a seperate function:

Code:
void SaveLoop(var wait_time)
{
	while(1)
	{
		save();
		wait(-wait_time);
	}
}



f.e. call SaveLoop(2); once and save(); gets called every 2 seconds without affecting the rest of your code.


Thank you very much! I tryed something simmilar, but my mistake was to call the function in my while(1) - so it was called every few miliseconds. But now I moved it to main and it does exactly what it should! Thanks again!
Posted By: elevationmind

Re: how do I tell the program to use a function only every second - 01/20/13 11:24

Originally Posted By: Uhrwerk
Originally Posted By: elevationmind
I know and tried that, but it doesn't help me because I don't want the program to wait ten seconds - I want something to happen every x seconds. How do I do that?

Do the tutorials. Seriously. http://tutorial.3dgamestudio.net/


So I did, but failed to find there anything that would help me. Could you direct me to the part of the information I might have missed that would have helped?
Posted By: Uhrwerk

Re: how do I tell the program to use a function only every second - 01/20/13 15:02

I think Workshop 10 - Entities is the best one for this. Workshop 2 and 3 are also related to the issue.
© 2024 lite-C Forums