if(key_e) running without input

Posted By: Stansmedia

if(key_e) running without input - 05/26/14 20:30

I've got some doors in my map that check the distance of the player, and when in range if the player presses the E key, it runs some commands. Now... it's running without keyboard input. The first door works fine, waits until you press E. But in the next level the door triggers without the keyboard input.

Code:
if(vec_dist(camera.x,my.x) < 40)
			{
				VECTOR temp; ANGLE temp2;
				
				vec_diff(temp,my.x,camera.x);
				vec_to_angle(temp2,temp);
				if((ang(temp2.pan-camera.pan) < 45) && (ang(temp2.pan-camera.pan) > -45)) //test visibility so vec_to_screen doesn't display when facing opposite
				{
					VECTOR* vTextpos = vector(my.x,my.y,my.z);
					vec_to_screen(vTextpos,camera);   // convert to screen coordinates
					if(vTextpos != NULL)
					{
						if(items >= 2) // item collected?
						{
							draw_text("Press E to open the door",vTextpos.x,vTextpos.y,vector(0,0,255));
							if(key_e)
							{
								snd_play(door,100,0);
								my.skill10 = 1; // terminate loop and run level_load at end of function
				      		
							}						
						}
						else
						{
							draw_text("You're missing a required item",vTextpos.x,vTextpos.y,vector(0,0,255));
						}
					}
				}
			}

Posted By: Anonymous

Re: if(key_e) running without input - 05/26/14 23:05

How did you call the function? Like this?
Code:
on_e = door_function;


If that was the last function called in your first level, it's possible the key press carried over to the start of your next level. Add these lines to the start of your door function (both doors) and see if it helps
Code:
while(key_e){wait(1);}
//wait for the key to be released before running the function

Posted By: Kartoffel

Re: if(key_e) running without input - 05/27/14 07:47

Originally Posted By: tolu619

Code:
on_e = door_function();



That's a function call...

You have to assign it linke this:
on_e = door_function;
Posted By: Anonymous

Re: if(key_e) running without input - 05/27/14 08:00

Originally Posted By: Kartoffel
Originally Posted By: tolu619

Code:
on_e = door_function();



That's a function call...

You have to assign it linke this:
on_e = door_function;


My bad. I knew that. I'll go correct my original post.
Posted By: Stansmedia

Re: if(key_e) running without input - 05/27/14 16:16

So I can't have it running in a loop of an action?

action ...
{
while(1)
{
if(vec_dist(my.x,player.x) < 32)
{
if(key_e)
level_load
...
Posted By: 3run

Re: if(key_e) running without input - 05/27/14 16:42

Originally Posted By: Stansmedia

Code:
action ...
{
	while(1)
	{
		if(vec_dist(my.x,player.x) < 32)
		{
			if(key_e)
			level_load
			...


The thing is (I might be wrong) that all instructions in those brackets (key_e) will run till loop is actually running.
You don't want to change your level endlessly, right?
You could insert 'break' after 'level_load', but that's not a good idea (probably), but it will work for sure!


Greets
Posted By: Uhrwerk

Re: if(key_e) running without input - 05/27/14 17:06

If it is an action it will be terminated by the level_load anyways. So no need for break, return or whatever...
Posted By: Anonymous

Re: if(key_e) running without input - 05/28/14 09:28

Normalization is always a good idea. Normalize till it hurts, denormalize until it hurts. Put re-usable things in separate functions and then call them from other actions/functions. You could store the name of the next level as a global parameter in each level then pass the name of the next level into your key_e function each time. If my post needs further explanation or some sample code, I'll be glad to oblige.
Posted By: Wjbender

Re: if(key_e) running without input - 07/03/14 21:19

i see you switching this to 1
my.skill10 = 1;

but in your else clause I do not see you switching
it to =0 .

I did not read the rest , I assumed thats your run
status switch. ..
© 2024 lite-C Forums