• 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 Changing an interactive menu in the first room based off actions in further rooms

R

Royms

Guest
I am using GameMaker Professional v. 1.4 with a mix of drag and drop and code.
At the start of the game, I have a menu where the player can choose the game mode by clicking on an icon, and the levels in that mode are displayed as their own icons:
game maker forum.jpg
I want these icons to change based on whether or not the player has already beaten that particular level:
game maker forum 2.jpg
I tried doing this using global variables, but since GameMakers seems to require that global variables be assigned values upon declaration, I cannot use them in the start room. For example, when I put something like this in the start room's creation code:

global.level_1_beat=0

It undoes the assignment of the "level_1_beat" variable to a true value when the level was actually beaten. I could declare the global variables in a new room placed before the start menu room, but this seems like an inefficient use of resources.
I also tried creating persistent objects for each level that are created when the levels are beaten. These objects can then be made visible only when the level icon is displayed in the start room. This doesn't work, because for some odd reason, the object that creates these "level beaten" objects destroys the previous one created. If I beat the first level and then go back to the start menu, the "level 1 beaten" object will be displayed, but then when I beat level 2, the game creates the "level 2 beaten" object, but then destroys, the "level 1 beaten" object.
Is there a way to get either of these methods to work, or is there another method?
 
Use ini files.

When the menu room loads, put this in the menu controllers Create Event. If the level hasn't been beaten yet, the default value of 0 will apply.
Code:
ini_open("Settings.ini")
global.level_1_beat=ini_read_real("levels", "level_1_beat", 0); // 0 is default if ini has not been created/changed yet
ini_close();
Then you can check the value of global.level_1_beat and adjust your menu accordingly.

When the player beats the level
Code:
ini_open("Settings.ini")
ini_write_real("levels", "level_1_beat", 1); // Set to 1 because its been beaten
ini_close();
Now, when the player goes back to the menu, level_1_beat will be loaded as 1 from the ini file.
 
Last edited:

Nidoking

Member
If you create a persistent instance, you can put the code to initialize the menu (from the ini file or however) in its Game Start event rather than Create. That will only ever run once, so it won't overwrite any changes.
 
I made a copy-paste error above. Ive edited the original post.

This :
global.level_1_beat=ini_write_real("levels", "level_1_beat", 1); // Set to 1 because its been beaten

should just appear like this:
ini_write_real("levels", "level_1_beat", 1); // Set to 1 because its been beaten
 
Top