IsNow when I exit out of fullscreen mode and run my script for resizing the window, it gets stuck in some kind of loop of resizing the window, causing it to get really big and constantly flash.
My script for resizing the window:
Also, it keeps giving me errors when I try to load my game and run a DS Map check for my objects since I'm storing their state in the save file. The specific error for pretty much every object is:GML:function scr_ScreenMode() { if (global.display_mode = 0) { window_set_fullscreen(false); if global.dos_aspect_ratio = 0 { window_set_size(320,200); surface_resize(application_surface,320,200); } if global.dos_aspect_ratio = 1 { window_set_size(320,240); surface_resize(application_surface,320,240); } } if (global.display_mode = 1) { window_set_fullscreen(false); if global.dos_aspect_ratio = 0 { window_set_size(640,400); surface_resize(application_surface,640,400); } if global.dos_aspect_ratio = 1 { window_set_size(640,480); surface_resize(application_surface,640,480); } } if (global.display_mode = 2) { window_set_fullscreen(false); if global.dos_aspect_ratio = 0 { window_set_size(1280,800); surface_resize(application_surface,1280,800); } if global.dos_aspect_ratio = 1 { window_set_size(1280,960); surface_resize(application_surface,1280,960); } } if (global.display_mode = 3) { if global.dos_aspect_ratio = 0 { window_set_fullscreen(true); surface_resize(application_surface,1280,800); gpu_set_tex_filter(true); } if global.dos_aspect_ratio = 1 { window_set_fullscreen(true); surface_resize(application_surface,1280,960); gpu_set_tex_filter(true); } } }
ds_map_find_value argument 1 incorrect type (undefined) expecting a Number (YYGI32)
I have the following code in the creation event of each object that I want to change the state of:
ctrl_GameState Create event:GML:key = scr_GameStateGetKey(); var _game_state = ds_map_find_value(ctrl_GameState.game_state,key); if(!is_undefined(_game_state) && _game_state==false) instance_destroy(); else ;
The scr_GameStateGetKey script:GML:/// @description Create DS Map game_state = ds_map_create();
I read the patch notes and came across this:GML:function scr_GameStateGetKey() { return room_get_name(room)+object_get_name(object_index)+string(x)+string(y); }
I guess I will have to try and refactor my code to make it work.
ctrl_GameState
beeing created before all the other instances?![ALTERNATIVE SOLUTION]
You can have the gameState map stored inside a function as static variable.
Static variables are variables that are declared once and only once when the function/constructor is first executed.
For example inside a GML script add the following function:
GML:
function getGameState() {
static game_state = ds_map_create(); // this will only run the first time you execute the function, so only one will be created.
return game_state;
}
function gameStateGetKey(key) {
static game_state = getGameState();
return ds_map_exists(game_state, key) ? game_state[? key] : show_error("[ERROR] No such key in GameState", true);
}
function gameStateSetKey(key, value) {
static game_state = getGameState();
game_state[? key] = value;
}
GML:
var result = gameStateGetKey("myKey");
and the beauty of this is that if you never call the method the ds_map never gets created. it's something that is not there until you look for it.
[NOTE]
if you need extra process on the gamestate map you can still have a
ctrl_GameState
and on its create event you just do.
GML:
game_state = getGameState();
[EXTRA]
The solution/setup I'm providing, assumes the game_state ds_map is something global that should exist always when your game is running and it's not a thing that you want to destroy and create multiple times along the game execution.
[SCREEN RESIZE]
Regarding the screen resize:
I rewrote the function you posted:
GML:
function scr_ChangeScreenMode(_mode, _ratio) {
switch (_mode) {
case 0:
window_set_fullscreen(false);
if (_ratio == 0) {
window_set_size(320,200);
surface_resize(application_surface,320,200);
}
else if (_ratio == 1) {
window_set_size(320,240);
surface_resize(application_surface,320,240);
}
break;
case 1:
window_set_fullscreen(false);
if (_ratio == 0) {
window_set_size(640, 400);
surface_resize(application_surface, 640, 400);
}
else if (_ratio == 1) {
window_set_size(640,480);
surface_resize(application_surface, 640, 480);
}
break;
case 2:
window_set_fullscreen(false);
if (_ratio == 0) {
window_set_size(1280, 800);
surface_resize(application_surface, 1280, 800);
}
else if (_ratio == 1) {
window_set_size(1280, 960);
surface_resize(application_surface, 1280, 960);
}
break;
case 3:
window_set_fullscreen(true);
if (_ratio == 0) {
surface_resize(application_surface, 1280, 800);
}
else if (_ratio == 1) {
surface_resize(application_surface, 1280, 960);
}
gpu_set_tex_filter(true);
break;
}
}
global.
inside the functions use arguments and then pass the global variables in:This will make code much clean and easier to maintain.
GML:
scr_ChangeScreenMode(global.display_mode, global.dos_aspect_ratio)
scr_ScreenMode
?!
Last edited: