Posted By: 3run
on_ and file_dialog - 04/28/18 23:53
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:
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(""); }