• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Windows troubleshooting game slow down

F

Farouk

Guest
Hi
my game sometimes slows down, the same way programs slow down when they are about to freeze

how can i trouble shoot that?
any tips?
 
Use the debugger to check memory usage and instance count. Make sure you are not spawning many instances accidentally.

Make sure if you are using data structures that you are managing them properly and not creating them over and mover by mistake.
 
F

Fishman1175

Guest
You can also use the debugger’s Profiler tool to see exactly what code is slow.
 
F

Farouk

Guest
Thank you guys,
just a related question

do file open requests to ini files , and file writes slow down the game?
 

Hyomoto

Member
Yes. They certainly do. If you intend to do it constantly, you'd be better off converting your file into some type of data type and then writing it to a file when you are done with it. Take this odd example:
Code:
if ds_list_size( debug.logEntries ) > debug_log_interval {
    debug_log_write();
   
}
Code:
/// @func debug_log_write();
var _file = file_text_open_append( "log.txt" );

for ( var _i = 0; _i < ds_list_size( debug.logEntries ); _i++ ) {
    file_text_write_string( _file, debug.logEntries[| _i ] );
    file_text_writeln( _file );
   
}
file_text_close( _file );

ds_list_empty( debug.logEntries );
In this case, we check if the number of entries in the log has reached some threshold before writing it to disk rather than writing them every time the log is added to. The whole idea is the prevent from calling this often, as writing and reading to disk is much slower than to memory. On the other hand, if you happen to be saving some piece of information into a file:
Code:
/// @func file_get( filename )
/// @param {string}        filename
var _filename    = argument0;
var _list        = ds_list_create();
var _string, _file;

ds_list_clear( _list );

if !file_exists( _filename ) { log( "file_get :: failed, " + _filename + " not found" ) }
else {
    _file    = file_text_open_read( _filename );
   
    while ( !file_text_eof( _file ) ) {
        _string    = file_text_read_string( _file ); file_text_readln( _file );
       
        if string_lettersdigits( _string ) == "" { continue }
       
        ds_list_add( _list, _string );
       
    }
    file_text_close( _file );
   
}
return _list;
In this example, we are reading out our entire file to a ds_list. Now we can do whatever we want with it, even write it back. The important part is that the file is now in memory where it can be accessed quickly and easily. You'll notice the theme between both of these ideas is that we are trying to reduce the amount of interaction with have with the files on the disk by keeping them in memory before we read or write to them.
 
F

Farouk

Guest
thank you guys
what about a highscore that needs to be updated constantly as the person increases their score?

something like this in a step event:

ini_open("highscore.ini");
highscorevar= ini_read_real("highscoretable","h_score",0);
if myscore > highscorevar
{
ini_write_real("highscoretable","h_score",myscore);
}
ini_close();
 

Hyomoto

Member
As long as you were only running this when the player finishes a level or gets a game over, that wouldn't be an issue. That's mostly what myself and @IndianaBones are getting at: writing to the files is fine as long as you aren't constantly doing it. But there are problems in your example. If you were to keep beating the high score you'd be constantly opening and closing this file, which is not good. Secondly, why wouldn't you just read the high score into some variable and just check that? It would be much better to have the high score table saved into memory, read when the game starts and written when the game ends.

Generally you want to avoid constantly opening and closing files. Even if your game runs fine, it's also just a really bad habit to get into.
 
F

Farouk

Guest
As long as you were only running this when the player finishes a level or gets a game over, that wouldn't be an issue. That's mostly what myself and @IndianaBones are getting at: writing to the files is fine as long as you aren't constantly doing it. But there are problems in your example. If you were to keep beating the high score you'd be constantly opening and closing this file, which is not good. Secondly, why wouldn't you just read the high score into some variable and just check that? It would be much better to have the high score table saved into memory, read when the game starts and written when the game ends.

Generally you want to avoid constantly opening and closing files. Even if your game runs fine, it's also just a really bad habit to get into.

makes sense
thank you!
 
Top