Gamestudio Links
Zorro Links
Newest Posts
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
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 1,241 guests, and 11 spiders.
Key: Admin, Global Mod, Mod
Newest Members
AemStones, LucasJoshua, Baklazhan, Hanky27, firatv
19058 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Slow Function #406111
08/13/12 22:08
08/13/12 22:08
Joined: Jul 2008
Posts: 168
8
82RJZAE Offline OP
Member
82RJZAE  Offline OP
Member
8

Joined: Jul 2008
Posts: 168
Hi, does anyone know why the below function causes my player movement code to run slow once I added:

Code:
key_shoot_on=0;
...
if(key_pressed(key_for_str(key_shoot)))
key_shoot_on=1;

to
Code:
STRING* key_forward = "w";
STRING* key_backward = "s";
STRING* key_left = "a";
STRING* key_right = "d";
STRING* key_jump = "space";
STRING* key_run = "shiftl";
STRING* key_action = "e";
STRING* key_shoot = "mouse_left";

void handle_keyboard_input()
	{
		while(player.skill1>0){
		key_forward_on=0;
		key_backward_on=0;
		key_left_on=0;
		key_right_on=0;
		key_jump_on=0;
		key_run_on=0;
		key_shoot_on=0;
		
		if(key_pressed(key_for_str(key_forward)))
			key_forward_on=1;
		if(key_pressed(key_for_str(key_backward)))
			key_backward_on=1;
		if(key_pressed(key_for_str(key_left)))
			key_left_on=1;
		if(key_pressed(key_for_str(key_right)))
			key_right_on=1;
		if(key_pressed(key_for_str(key_jump)))
			key_jump_on=1;
		if(key_pressed(key_for_str(key_run)))
			key_run_on=1;
		if(key_pressed(key_for_str(key_shoot)))
			key_shoot_on=1;
		wait(1);
		}
	}


When I added the last check for the key pressed it caused my player movement code to move very slowly. Also, it prevented me from pressing F11 to open up the debug panel. My guess is that I've reached some sort of limit. Can anyone suggest a work around method of capturing keyboard input? I would like to have the keys set in a STRING* at the top of my code so that they can be remapped later.

Thank,
82RJZAE

Re: Slow Function [Re: 82RJZAE] #406115
08/13/12 23:20
08/13/12 23:20
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Check the manual (key_for_str), mouse_left is not listed there.
Btw. you can speed your function up a little by calling key_for_str only once for each string and save the result in a variable.


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Slow Function [Re: Superku] #406125
08/14/12 08:08
08/14/12 08:08
Joined: Jan 2004
Posts: 3,023
The Netherlands
Helghast Offline
Expert
Helghast  Offline
Expert

Joined: Jan 2004
Posts: 3,023
The Netherlands
I made a RPG template, which you can download in AUM100, which does mapping of keys like you have, but reads it from an external .ini file.
This one does not have any slowdown, and is made in a seperate script, so all you have to do is include it, and you can use it straight away.

regards,


Formerly known as dennis_fantasy
Portfolio - http://www.designorhea.com/
Project - http://randomchance.cherrygames.org/

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