[C-Script] Stroboscope

Posted By: Polypfreak1987

[C-Script] Stroboscope - 05/03/09 18:09

Hello everbody,

I want to make a stroboscope. I have a model with an action:

Code:
action stroboscoop {
	while(1) {
		if(key_space == 1) {
			strobo();
		}
		wait(1);
	}
}


And the following function:

Code:
function strobo() {
	vec_set(my.blue,vector(255,255,255));
	if(key_space == 1) {
		while(1) {
			my.lightrange = 200;
			wait(-0.01);
			my.lightrange = 0;
			wait(-0.01);
		}
	}
}


When I press the spacebar the light will flicker. But when I release the spacebar the light continues flickering. Does anybody know how to stop that?

So when I press the spacebar. The light will flicker as long the spacebar is pressed. When I release the spacebar, the flicker will stop.

I hope you can help me out.

Thanks in advance.
Posted By: Widi

Re: [C-Script] Stroboscope - 05/03/09 18:17

while(1) means that the loop never ending, it is always true (1).
remove the if () and the while(), and use:
while (key_space) // it is true if the space key is pressed
{
...
}
Posted By: Polypfreak1987

Re: [C-Script] Stroboscope - 05/03/09 18:43

Thank you for your answer. Now I have the following problem. When I press the spacebar the light will be on, but not flicker. This is the code:

Code:
function strobo() {
	vec_set(my.blue,vector(255,255,255));
	while(key_space) {
		my.lightrange = 200;
		wait(-0.01);
		my.lightrange = 0;
		wait(-0.01);
	}
}

action stroboscoop {
	while(1) {
		if(key_space == 1) {
			strobo();
		}
		wait(1);
	}
}

Posted By: Widi

Re: [C-Script] Stroboscope - 05/03/09 19:02

maybe the wait time is to short. Use "wait(1)" , that wait for one frame...
Posted By: Polypfreak1987

Re: [C-Script] Stroboscope - 05/03/09 19:10

Tried it, but didn't work.
Posted By: Shadow969

Re: [C-Script] Stroboscope - 05/03/09 19:33

in your original code, replace while(1) with if(key_space) and visa versa
Posted By: Widi

Re: [C-Script] Stroboscope - 05/03/09 19:36

maybe this helps:

Code:
while (1)
{
   if (key_space) 
   {
      strobo();
      while (key_space)  wait(1); // wait here untill key_space = 0, strobo() would be call only one time.
   }
   wait(1);
}

Posted By: Polypfreak1987

Re: [C-Script] Stroboscope - 05/04/09 04:45

Thanks, that worked for me. laugh
Posted By: Germanunkol

Re: [C-Script] Stroboscope - 05/07/09 19:29

I think the problem was that you were calling the function strobo whenever key_space was pressed, since you held the spacebar down, it was called anew every frame, so the line:vec_set(my.blue,vector(255,255,255)); was executed every frame and then it doesn't flicker.
© 2024 lite-C Forums