Gamestudio Links
Zorro Links
Newest Posts
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
1 registered members (TedMar), 1,420 guests, and 3 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
[C-Script] Stroboscope #263997
05/03/09 18:09
05/03/09 18:09
Joined: Aug 2006
Posts: 96
Netherlands
P
Polypfreak1987 Offline OP
Junior Member
Polypfreak1987  Offline OP
Junior Member
P

Joined: Aug 2006
Posts: 96
Netherlands
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.

Re: [C-Script] Stroboscope [Re: Polypfreak1987] #263998
05/03/09 18:17
05/03/09 18:17
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
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
{
...
}

Re: [C-Script] Stroboscope [Re: Widi] #264003
05/03/09 18:43
05/03/09 18:43
Joined: Aug 2006
Posts: 96
Netherlands
P
Polypfreak1987 Offline OP
Junior Member
Polypfreak1987  Offline OP
Junior Member
P

Joined: Aug 2006
Posts: 96
Netherlands
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);
	}
}


Re: [C-Script] Stroboscope [Re: Polypfreak1987] #264007
05/03/09 19:02
05/03/09 19:02
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
maybe the wait time is to short. Use "wait(1)" , that wait for one frame...

Re: [C-Script] Stroboscope [Re: Widi] #264008
05/03/09 19:10
05/03/09 19:10
Joined: Aug 2006
Posts: 96
Netherlands
P
Polypfreak1987 Offline OP
Junior Member
Polypfreak1987  Offline OP
Junior Member
P

Joined: Aug 2006
Posts: 96
Netherlands
Tried it, but didn't work.

Re: [C-Script] Stroboscope [Re: Polypfreak1987] #264011
05/03/09 19:33
05/03/09 19:33
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
in your original code, replace while(1) with if(key_space) and visa versa

Re: [C-Script] Stroboscope [Re: Polypfreak1987] #264012
05/03/09 19:36
05/03/09 19:36
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
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);
}


Last edited by Widi; 05/03/09 19:42.
Re: [C-Script] Stroboscope [Re: Widi] #264057
05/04/09 04:45
05/04/09 04:45
Joined: Aug 2006
Posts: 96
Netherlands
P
Polypfreak1987 Offline OP
Junior Member
Polypfreak1987  Offline OP
Junior Member
P

Joined: Aug 2006
Posts: 96
Netherlands
Thanks, that worked for me. laugh

Re: [C-Script] Stroboscope [Re: Polypfreak1987] #264721
05/07/09 19:29
05/07/09 19:29
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline
Expert
Germanunkol  Offline
Expert

Joined: Jun 2006
Posts: 2,640
Earth
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.


~"I never let school interfere with my education"~
-Mark Twain

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