• 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!

HTML5 ds_grid_read causing game to freeze

Jezla

Member
I'm implementing a local high score system for my new game using a ds_grid. When the player is out of lives, his name and score are saved to a ds_grid and displayed on a high score screen. The ds_grid is written to a string and saved to an ini file. When the game is starts, the ds_grid is created, then set by reading the ssaved string from the ini file. This works fine on a Windows export.

When I export to HTML5, the game freezes or hangs on the ds_grid_read call. The ds_grid is created in a controller object in an initialization room. Here's the oMainController's create event code:

Code:
///Initialize game variables
global.level = 1;
global.players = PLAYER_ONE; //One or two players, one by default
global.Waves = 1; //Number of waves, same as level (level 1 = 1 wave, level 2 = 2 waves, etc.)
global.waveNum = 5; //Number of enemies in each wave
global.PlayerOneLives = 5; //Players' lives
global.PlayerTwoLives = 5; //
global.enemy_count = 0;
global.spawn_count = 0;
global.spawn_stack = -1;
global.hp_stack = -1;
spawners = 0;
spawn_rate = (room_speed*3);
score = 0;
global.run = false; //whether the game is running or not

//View settings
base_width = 320;
base_height = 200;
width = base_width;
height = base_height;

//Draw settings
draw_set_color(c_white);
draw_set_font(fnt_main);
lvl_str = "";
draw_str = false;
alpha = 0; //alpha for start text
alarm[5] = room_speed; //alpha alarm


//States
enum st {
   
        normal,
        mad,
        stunned,
        death
       
    }

//High Score indices
enum hs {

        name = 0,
        val = 1
       
    }

   
//Create the High Score Table
global.HighScores = ds_grid_create(2, 10);

//Populate the grid

ini_open("hs.ini");
ds_grid_read(global.HighScores, ini_read_string("HS", "scores", ""));
ini_close();


//Go to Game
room_goto_next();

If I comment out the ds_grid_read call, the game runs normally (except that the high scores are not loaded at the start). I've tried running opening the debug console in the browser, and while I can't make much sense of it, it seems to point me at a JSON. parse error. I looked that up and it seems to me that the string that the grid is written to is in an incorrect format or something. This is a little over my head. Am I correct in identifying the problem, and if so, how do I correct it so it works?

EDIT: I should also add that while the game freezes, it's not unresponsive. I can use a keyboard control to advance to the next room (which is not intentional, but is a happy mistake in this case), the start room. I can then proceed with the game, except that the controller's alarm[5] either doesn't run or doesn't execute (it changes the alpha variable value).
 
C

cutch22

Guest
My ds_grid_read doesn't work on html5 either. I think it's a bug, but it's over my head as well. If someone has a work around that'd be great!
 
P

ph101

Guest
What step is your ds_grid_read in - and is there anything to prevent it doing so every step?

edit. ok I see it's in create code.
 
Last edited by a moderator:

Llama_Code

Member
Have you checked the browsers local storage to ensure the INI file exists properly?

You don't have any error handling in your file reading so that could be an issue.
 

Jezla

Member
Have you checked the browsers local storage to ensure the INI file exists properly?

You don't have any error handling in your file reading so that could be an issue.
I feel silly, but I tried to find the file, but I'm not sure where the browser's local storage is.

I ended up solving the problem by using a ds_grid for windows and a 2d array for HTML5. Not ideal, but I was able to get the game done in time. Still, I appreciate any insight you can offer, it will help for future projects I'm sure!
 

Llama_Code

Member
In Chrome, start your game, then hit F12 to bring up the dev console, then click the Application tab and on the left of the console look for local storage, expand that and click on the URL for your game. On the right of the console you will see two columns, key and value. Key should be the name of your INI file and value would be its contents, so for one make sure its there, and for two make sure it contains what you expect.

In the future, when dealing with files it is always a good practice to ensure it exists before trying to read from it. If you are trying to write to a non existing file GameMaker would just create it, but not so if you are trying to read from it. If you try to read from a non existing file it should return a default value, but I have seen that fail before, and the default value may not be what your expecting. So your code above:

Code:
ini_open("hs.ini");
ds_grid_read(global.HighScores, ini_read_string("HS", "scores", ""));
ini_close();
Should at the very least be somehing like:

Code:
if (file_exists("hs.ini"))
{
ini_open("hs.ini");
ds_grid_read(global.HighScores, ini_read_string("HS", "scores", ""));
ini_close();
}
else
{
// do something for file there, probably create one.
}
Now that may not have been your issue but its something to look at.

I would also suggest getting comfortable with your browsers development console if your going to create HTML5 games, as you will use it often. There are some great tutorials on YouTube.
 
Top