Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (howardR, 7th_zorro), 893 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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 Offline OP
Serious User
Stansmedia  Offline 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.

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));
						}
					}
				}
			}



Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
Re: if(key_e) running without input [Re: Stansmedia] #441554
05/26/14 23:05
05/26/14 23:05

T
tolu619
Unregistered
tolu619
Unregistered
T



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


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 Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
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;


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

T
tolu619
Unregistered
tolu619
Unregistered
T



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.

Re: if(key_e) running without input [Re: ] #441580
05/27/14 16:16
05/27/14 16:16
Joined: Mar 2003
Posts: 1,524
Canada
Stansmedia Offline OP
Serious User
Stansmedia  Offline OP
Serious User

Joined: Mar 2003
Posts: 1,524
Canada
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
...


Decessus - 80% done. 100% abandoned.
GET MY ANDROID GAME! https://play.google.com/store/apps/details?id=com.lasertrain.zspinballfree&hl=en
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 Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
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


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
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 Offline
Expert
Uhrwerk  Offline
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

T
tolu619
Unregistered
tolu619
Unregistered
T



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
W
Wjbender Offline
User
Wjbender  Offline
User
W

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

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