Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, monk12, Quad), 829 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
on_ and file_dialog #472458
04/28/18 23:53
04/28/18 23:53
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
I have two functions, let's call them 'save' and 'load'. In them I use 'file_dialog' and 'file_dialog_save' in order to save/load a file. To call those functions I use f4 (to call 'save') and f5 (to call 'load'). All is great, but I noticed that after first two calls, in order to call those functions I have to press f4 and f5 twice! Can anyone please explain why?

Best regards!

Edit: also noticed, that this results to not being able to close game's window by clicking on 'close' X at the upper right corner.. Could this be a memory issue? Pointers and such?

Edit2: thx God, this has nothing to do with my map editor in general, here is a small example, that has the same problem:
Code:
#include <acknex.h>
#include <default.c>
#include <windows.h>
#include <strio.c>

#define PRAGMA_POINTER

BMAP *temp_bmp = NULL;

void save_level(){
	
	char *map_file = file_dialog_save("Save level", "*.png");	
	if(map_file == NULL){ return(-1); }
	
	STRING *file_name_str = "";
	STRING *path_str = str_create(map_file);
	var e_pos = str_stri(path_str, ".png");
	
	if(e_pos == 0){
		
		var length = str_len(path_str);
		var n_pos = str_chr(path_str, -length, 92);
		str_cut(file_name_str, path_str, n_pos + 1, length);
		
	}
	else{
		
		var n_pos = str_chr(path_str, -e_pos, 92);
		str_cut(file_name_str, path_str, n_pos + 1, e_pos - 1);
		
	}
	
	str_cat(file_name_str, ".png");
	
	bmap_save(temp_bmp, file_name_str);
	
}

void load_level(){
	
	char *map_file = file_dialog("Load level", "*.png");
	if(map_file == NULL){ return; }	
	
	STRING *file_name_str = "";
	STRING *path_str = str_create(map_file);
	var e_pos = str_stri(path_str, ".png");
	
	if(e_pos == 0){
		
		var length = str_len(path_str);
		var n_pos = str_chr(path_str, -length, 92);
		str_cut(file_name_str, path_str, n_pos + 1, length);
		
	}
	else{
		
		var n_pos = str_chr(path_str, -e_pos, 92);
		str_cut(file_name_str, path_str, n_pos + 1, e_pos - 1);
		
	}
	
	str_cat(file_name_str, ".png");
	
	if(!file_exists(file_name_str)){ return; }
	temp_bmp = bmap_create(file_name_str);
	
}

void remove_level(){
	
	if(temp_bmp){ safe_remove(temp_bmp); }
	
}

void main(){
	
	on_f3 = remove_level;
	on_f4 = save_level;
	on_f5 = load_level;
	
	fps_max = 60;
	warn_level = 6;
	level_load("");
	wait(3);
	
	temp_bmp = bmap_createblack(256, 64, 32);
	bmap_fill(temp_bmp, COLOR_RED, 100);
	
	while(!key_esc){
		
		draw_text("F3 - remove\nF4 - save\nF5 - load", 10, 10, COLOR_WHITE);
		
		if(temp_bmp){
			
			draw_quad(temp_bmp, vector(256, 256, 0), NULL, NULL, NULL, NULL, 100, 0);
			
		}
		
		wait(1);
		
	}
	
	sys_exit("");
	
}


Last edited by 3run; 04/29/18 01:00.

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: on_ and file_dialog [Re: 3run] #472460
04/29/18 08:24
04/29/18 08:24
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
Kartoffel Offline
Expert
Kartoffel  Offline
Expert

Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
It's because acknex doesn't recognize the key being released when another window is in focus.

One cheap solution would be to wait until the key is released. Otherwise, using the windows API directly for input should work aswell.


POTATO-MAN saves the day! - Random
Re: on_ and file_dialog [Re: Kartoffel] #472462
04/29/18 09:34
04/29/18 09:34
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Hi,
that happens when you open any new window (file explorer, printf, error, etc) with a pressed key. The engine does not reset its pilot variable (key_... and key_any aswell), so they remain true although the new window is closed. I guess that happens because the key releasing windows event is received by the new window instead of its parent so engines key_... variables manager is never executed for that event. I thought that calling the engines windows callback function with the proper parameters might work but no luck.

Code:
// global prototype
UINT CALLBACK myMsgHandler (HWND hdlg, UINT uiMsg, WPARAM wParam, LPARAM lParam);
// save engines callback function
myMsgHandler = on_message;
// call it on_f5 event
myMsgHandler (hWnd, WM_KEYUP, VK_F5, 0);



Salud!

edited________
ups, late...

Last edited by txesmi; 04/29/18 09:44.
Re: on_ and file_dialog [Re: txesmi] #472463
04/29/18 09:46
04/29/18 09:46
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Hi guys!

Thank you for suggestions! Does it mean that windows API won't help here?

Edit: yes, 'key_pressed' shows that f4 and f5 are remaining pressed when file dialog windows get's closed...

Edit2: I found this in manual for 'key_pressed'
Quote:
number - scancode of the key to check, 8.30 or -1 for resetting all keys to the nonpressed state.
So maybe I need to call 'key_pressed(-1)' to reset all keys, right after the file windows was closed ?

Edit3: grin yes, this helped. Just call 'key_pressed(-1)' right after 'file_dialog' function. As a prove, here is edited example from first post:
Code:
#include <acknex.h>
#include <default.c>
#include <windows.h>
#include <strio.c>

#define PRAGMA_POINTER

BMAP *temp_bmp = NULL;

void save_level(){
	
	char *map_file = file_dialog_save("Save level", "*.png");	
	key_pressed(-1);
	if(map_file == NULL){ return(-1); }
	
	STRING *file_name_str = "";
	STRING *path_str = str_create(map_file);
	var e_pos = str_stri(path_str, ".png");
	
	if(e_pos == 0){
		
		var length = str_len(path_str);
		var n_pos = str_chr(path_str, -length, 92);
		str_cut(file_name_str, path_str, n_pos + 1, length);
		
	}
	else{
		
		var n_pos = str_chr(path_str, -e_pos, 92);
		str_cut(file_name_str, path_str, n_pos + 1, e_pos - 1);
		
	}
	
	str_cat(file_name_str, ".png");
	
	bmap_save(temp_bmp, file_name_str);
	
}

void load_level(){
	
	char *map_file = file_dialog("Load level", "*.png");
	key_pressed(-1);
	if(map_file == NULL){ return; }	
	
	STRING *file_name_str = "";
	STRING *path_str = str_create(map_file);
	var e_pos = str_stri(path_str, ".png");
	
	if(e_pos == 0){
		
		var length = str_len(path_str);
		var n_pos = str_chr(path_str, -length, 92);
		str_cut(file_name_str, path_str, n_pos + 1, length);
		
	}
	else{
		
		var n_pos = str_chr(path_str, -e_pos, 92);
		str_cut(file_name_str, path_str, n_pos + 1, e_pos - 1);
		
	}
	
	str_cat(file_name_str, ".png");
	
	if(!file_exists(file_name_str)){ return; }
	temp_bmp = bmap_create(file_name_str);
	
}

void remove_level(){
	
	if(temp_bmp){ safe_remove(temp_bmp); }
	
}

void main(){
	
	on_f3 = remove_level;
	on_f4 = save_level;
	on_f5 = load_level;
	
	fps_max = 60;
	warn_level = 6;
	level_load("");
	wait(3);
	
	temp_bmp = bmap_createblack(256, 64, 32);
	bmap_fill(temp_bmp, COLOR_RED, 100);
	
	while(!key_esc){
		
		draw_text("F3 - removenF4 - savenF5 - load", 10, 10, COLOR_WHITE);
		DEBUG_VAR(key_pressed(62), 100);
		DEBUG_VAR(key_pressed(63), 130);
		
		if(temp_bmp){
			
			draw_quad(temp_bmp, vector(256, 256, 0), NULL, NULL, NULL, NULL, 100, 0);
			
		}
		
		wait(1);
		
	}
	
	sys_exit("");
	
}

Thank you for clearing things out guys! Without you I wouldn't even understand why this happened. Was thinking about memory/pointers related issues grin

Last edited by 3run; 04/29/18 09:56.

Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: on_ and file_dialog [Re: 3run] #472464
04/29/18 10:00
04/29/18 10:00
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
you hit the clove! cool

I had found this problem last week and solved it by Kartoffels suggestion. Much better now, thanks to you!

Re: on_ and file_dialog [Re: txesmi] #472465
04/29/18 10:18
04/29/18 10:18
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline OP
Senior Expert
3run  Offline OP
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: txesmi
you hit the clove! cool
at least once I did grin ahah, thank you guys!

My best regards!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung

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