3 registered members (Ayumi, Akow, AndrewAMD),
1,505
guests, and 9
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
if(key_e) running without input
#441551
05/26/14 20:30
05/26/14 20:30
|
Joined: Mar 2003
Posts: 1,524 Canada
Stansmedia
OP
Serious User
|
OP
Serious User
Joined: Mar 2003
Posts: 1,524
Canada
|
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.
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));
}
}
}
}
|
|
|
Re: if(key_e) running without input
[Re: Stansmedia]
#441554
05/26/14 23:05
05/26/14 23:05
|
tolu619
Unregistered
|
tolu619
Unregistered
|
How did you call the function? Like this? 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
while(key_e){wait(1);}
//wait for the key to be released before running the function
Last edited by tolu619; 05/27/14 08:04. Reason: Corrected small bit of code
|
|
|
Re: if(key_e) running without input
[Re: ]
#441562
05/27/14 07:47
05/27/14 07:47
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
That's a function call... You have to assign it linke this: on_e = door_function;
POTATO-MAN saves the day! - Random
|
|
|
Re: if(key_e) running without input
[Re: Kartoffel]
#441564
05/27/14 08:00
05/27/14 08:00
|
tolu619
Unregistered
|
tolu619
Unregistered
|
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.
|
|
|
Re: if(key_e) running without input
[Re: Stansmedia]
#441581
05/27/14 16:42
05/27/14 16:42
|
Joined: May 2009
Posts: 5,370 Caucasus
3run
Senior Expert
|
Senior Expert
Joined: May 2009
Posts: 5,370
Caucasus
|
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
|
|
|
Re: if(key_e) running without input
[Re: 3run]
#441584
05/27/14 17:06
05/27/14 17:06
|
Joined: Jan 2002
Posts: 4,225 Germany / Essen
Uhrwerk
Expert
|
Expert
Joined: Jan 2002
Posts: 4,225
Germany / Essen
|
If it is an action it will be terminated by the level_load anyways. So no need for break, return or whatever...
Always learn from history, to be sure you make the same mistakes again...
|
|
|
Re: if(key_e) running without input
[Re: Uhrwerk]
#441599
05/28/14 09:28
05/28/14 09:28
|
tolu619
Unregistered
|
tolu619
Unregistered
|
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.
|
|
|
Re: if(key_e) running without input
[Re: Anonymous]
#442820
07/03/14 21:19
07/03/14 21:19
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
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. ..
Compulsive compiler
|
|
|
|