Gamestudio Links
Zorro Links
Newest Posts
Executing Trades on Next Bar Open
by vicknick. 06/13/24 08:51
Zorro Beta 2.61: PyTorch
by jcl. 06/10/24 14:42
New FXCM FIX Plugin
by flink. 06/04/24 07:30
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (AndrewAMD, RealSerious3D, BrainSailor), 1,265 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19059 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Lite-c key pressed question #255106
03/07/09 16:34
03/07/09 16:34
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
Hi everyone!
I just have a real quick question about a little code i made.
Here is the code:

if(key_space == 1)
{
my.z += 10;
}

My question is, is there is a way so that when you press the space key once, it will run my.z += 10 just once, and not keep running. So basically you press the space key, and it only runs the code once and then you have to release the space key and hit it again for it to run the code again.

Thanks!

Re: Lite-c key pressed question [Re: binsky33333] #255108
03/07/09 16:41
03/07/09 16:41
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
if(key_space)
{
while(key_space) { wait(1); }
my.z += 10;
}


that'll work smile


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/
Re: Lite-c key pressed question [Re: Helghast] #255112
03/07/09 18:01
03/07/09 18:01
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
Are there any other ways? Like a way where you have to release the space key in order for the my.z += 10 to work?

Last edited by binsky33333; 03/07/09 18:02.
Re: Lite-c key pressed question [Re: binsky33333] #255115
03/07/09 18:16
03/07/09 18:16
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
You could use the "on_space" function. IE:
Code:
function main()
{
   ...
   on_space=player_jump;  //call this just once
   ...
}

function player_jump()
{
   player_entity.z += 10;  //ME is not valid here
}
or a messier way (but still acceptble) would be
Code:
action your_action()
{
   var space_pressed = 0;   //before WHILE loop starts
   ...
   if(key_space==0)    
   {
      space_pressed = 0;
   }
   else    
   {
      space_pressed = 1;
      if(space_pressed==0)   my.z += 10;
   }
   ...
}



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Lite-c key pressed question [Re: EvilSOB] #255118
03/07/09 18:39
03/07/09 18:39
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
Thanks for the reply but neither or those worked?

Hmmm... i wonder what i should do?

Last edited by binsky33333; 03/07/09 19:01.
Re: Lite-c key pressed question [Re: binsky33333] #255120
03/07/09 19:05
03/07/09 19:05
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
Post the rest of the function/action it is in.


"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Lite-c key pressed question [Re: EvilSOB] #255121
03/07/09 19:08
03/07/09 19:08
Joined: Dec 2008
Posts: 56
B
binsky33333 Offline OP
Junior Member
binsky33333  Offline OP
Junior Member
B

Joined: Dec 2008
Posts: 56
Here you go:
Code:
action player_move
{
	player= me;
	wait(1);
	camera.genius = player;
	shift_sense= 2;
	
	
	while(player!=NULL)
	{
		//Walking function arrow keys
		move_vec[0]= (key_cuu - key_cud)*8*time;
		move_vec[1]= (key_comma - key_period)*6*time;
		
		//Stair Climbing and falling
		vec_set(temp,my.x);
   	temp.z -= 4000;
   	trace_mode = ignore_me+ignore_sprites+IGNORE_MODELS+USE_BOX;
   	move_vec.z=(-trace(my.x,temp))*3*time;
	   player.pan -= (key_force.x)*1.5*time;
	   move_mode = IGNORE_YOU + IGNORE_PASSABLE + IGNORE_PUSH + ACTIVATE_TRIGGER + GLIDE;
  	   ent_move(move_vec,NULLVECTOR);
  	   
  	   //jumping
	
		
		//Running with arrow keys
		if(key_shift == 1)
		{
			move_vec[0]= (key_cuu - key_cud)*4*time;
		}
		player.pan += (key_cul - key_cur)*2*time;
		ent_move(move_vec,NULLVECTOR);
		if(move_vec[0]== 0 && move_vec[1]==0)
		{
			//Idle
		idle_percent= (idle_percent +5*time)%100;
		ent_animate(me,"stand",idle_percent,ANM_CYCLE);
	}
	else
	{
		//Running animation
		if(key_shift)
		{
			run_percent = (run_percent + sign(move_vec[0])*5*time)%100; 
			ent_animate(player,"run",run_percent,ANM_CYCLE); 
		}
		else
		{
		//Walking animation
		walk_percent = (walk_percent+ sign(move_vec[0])*5*time)%100;
		ent_animate(player,"walk",walk_percent,ANM_CYCLE);
	   }
   }
   

	   //The Camera
		vec_set(Camera.x,player.x);
		camera.z += 39;
		camera.pan = player.pan;
		temptilt += (key_pgup - key_pgdn)*4*time;
	   if(key_home){ temptilt =0;}
		if (temptilt > 75)
		{
			temptilt = 75;
			
		}
		else
		{
			if(temptilt < -75)
			{
				temptilt= -75;
			}
		}
		camera.tilt =0 +temptilt;
		wait(1);
	}
}


Re: Lite-c key pressed question [Re: binsky33333] #255130
03/07/09 20:01
03/07/09 20:01
Joined: Feb 2008
Posts: 3,232
Australia
EvilSOB Offline
Expert
EvilSOB  Offline
Expert

Joined: Feb 2008
Posts: 3,232
Australia
I cant see anywhere in the code mentioning trying to use the space key,
so I'll guess its the apparently blank junping section.

Code:
action player_move
{
	player= me;
	wait(1);
	camera.genius = player;
	shift_sense= 2;
	var space_held = 0;         //<<Added
	
	while(player!=NULL)
	{
		//Walking function arrow keys
		move_vec[0]= (key_cuu - key_cud)*8*time;
		move_vec[1]= (key_comma - key_period)*6*time;
		
		//Stair Climbing and falling
		vec_set(temp,my.x);
   	temp.z -= 4000;
   	trace_mode = ignore_me+ignore_sprites+IGNORE_MODELS+USE_BOX;
   	move_vec.z=(-trace(my.x,temp))*3*time;
	   player.pan -= (key_force.x)*1.5*time;
	   move_mode = IGNORE_YOU + IGNORE_PASSABLE + IGNORE_PUSH + ACTIVATE_TRIGGER + GLIDE;
  	   ent_move(move_vec,NULLVECTOR);

  	   
		//jumping
		if(key_space==0)    
			space_pressed = 0;
		else    
		{
			space_pressed = 1;
			if(space_pressed==0)   player.z += 10;
		}
	
		
		//Running with arrow keys
		if(key_shift == 1)
		{
			move_vec[0]= (key_cuu - key_cud)*4*time;
		}
		player.pan += (key_cul - key_cur)*2*time;
		ent_move(move_vec,NULLVECTOR);
		if(move_vec[0]== 0 && move_vec[1]==0)
		{
			//Idle
		idle_percent= (idle_percent +5*time)%100;
		ent_animate(me,"stand",idle_percent,ANM_CYCLE);
	}
	else
	{
		//Running animation
		if(key_shift)
		{
			run_percent = (run_percent + sign(move_vec[0])*5*time)%100; 
			ent_animate(player,"run",run_percent,ANM_CYCLE); 
		}
		else
		{
		//Walking animation
		walk_percent = (walk_percent+ sign(move_vec[0])*5*time)%100;
		ent_animate(player,"walk",walk_percent,ANM_CYCLE);
	   }
   }
   

	   //The Camera
		vec_set(Camera.x,player.x);
		camera.z += 39;
		camera.pan = player.pan;
		temptilt += (key_pgup - key_pgdn)*4*time;
	   if(key_home){ temptilt =0;}
		if (temptilt > 75)
		{
			temptilt = 75;
			
		}
		else
		{
			if(temptilt < -75)
			{
				temptilt= -75;
			}
		}
		camera.tilt =0 +temptilt;
		wait(1);
	}
}



"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial
Re: Lite-c key pressed question [Re: EvilSOB] #255132
03/07/09 20:18
03/07/09 20:18
Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
Xarthor Offline
Expert
Xarthor  Offline
Expert

Joined: Jul 2002
Posts: 4,436
Germany, Luebeck
@EvilSOB:
You reckon that your code will never execute the "my.z += 10;" part?
The problem is this section:
Code:
space_pressed = 1;
if(space_pressed==0)   player.z += 10;

First you set space_pressed to 1 and then check if its 0. But at that point it'll never be 0 because you set it to 1 first.

Try replacing the whole jumping part with:
Code:
if(key_space} 
{
  space_pressed = 1;
}
else
{
  if(space_pressed)
  {
    space_pressed = 0;
    my.z += 10;
  }
}


Re: Lite-c key pressed question [Re: Xarthor] #255139
03/07/09 23:24
03/07/09 23:24
Joined: Oct 2004
Posts: 1,655
T
testDummy Offline
Serious User
testDummy  Offline
Serious User
T

Joined: Oct 2004
Posts: 1,655
Code:
#define k_space 57
//define k_space = 57;
var k_nSt[50];
var in_n1 = 0;
var in_n2 = 0;

function kf2(var _nScanCode) {
	in_n1 = key_pressed(_nScanCode);
	in_n2 = in_n1 && !k_nSt[_nScanCode];
	k_nSt[_nScanCode] = in_n1;
	return(in_n2);
}
// usage:
if (kf2(k_space)) {

}


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