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

Legacy GM Strange issue with ds_map and room IDs

TobyMoby

Member
Dear fellow developers

I've recently run into a rather strange issue with my current project.
Some Info: I'm making a platforming game with a overworld for level selection.

Now, I create a ds_map of the levels with the key being a number from 1 to the total number of levels, and the value being the corresponding room ID.
So under key 1 there is the room ID of level 1 and so on. I do this, so I can later enter the levels according the a variable called var_lvl, holding the current level number.

So at the overworld, this variable (var_lvl) is changed through a collision between the player object and the different level icons on the overworld map. If you move your player over the level 1 icon, the variable is changed to var_lvl=1.

In a controller object, I do the following:
Code:
//create the ds_map
global.dsm_levels=ds_map_create();

//instert the room IDs into the
ds_map_replace(global.dsm_levels, 1, r_lvl1);
ds_map_replace(global.dsm_levels, 2, r_lvl2);

//...and so on.
Inside the player object of the overworld map:
Code:
if keyboard_check_pressed(vk_space)
{
     room_goto(global.dsm_levels[? var_lvl]
}
If I run the game and try this out, it throws me an error that tells me that room ID 13000163 (or similar, I'm not currently on my dev-PC).
If I draw the variable r_lvl1 (which holds the room ID) onto the screen, it simply says "1" or "2". So what's going on here? If the variable clearly holds "1" or "2", then how come does it searches for a strange number if I write the value into a DS and try to read it later? Is there some strange behavior I'm not aware of?

It seemed like such a simple thing, so it somehow frustrates me that it's not working as I think it should :/

Could anyone clear things up for me? That would be much appreciated!
If you need further clarification about an aspect of my problem, feel free to ask!

Best regards,
Toby
 

Simon Gust

Member
First thing I'd change is ds_map_replace with ds_map_add. The manual says ds_map_replace() is ok, but just to be sure.

Can you show the code where var_lvl is set? Probably relevant.

Make sure that var_lvl is a global variable so that both the controller and the player object handle the same variable.
 
I feel it should be mentioned also that if you're just using sequential numbers for the key, you might want to consider just using a ds_list. A map is a little overkill in this case
 

TobyMoby

Member
Hello guys!

Thank you all for your replys and your tips.
And I apologise, @TheouAegis is right of course, but I was at work and the problem didn't let my mind rest, so I tried to tell you about my problem as good as I could, but yes, I should have just waited til afternoon and copy my code.

BUT, I found out why it didn't work and it's pretty embarrassing. I used the same ds_map for two different purposes. One for the room IDs, and also for the IDs of the level objects on the world map.
This is what happens if you're not careful and work at something, then leave your game rest for quite a while and return to it with a great idea, smh.

@stainedofmind yes, a ds_list is exactly what I need! I somehow thought they were not in order, but according to the manual they are!

I now handle things with asset_get_index(), because my level-rooms follow a certain syntax with a number at the end :)

So thank you guys, see you next time on:
HOW TO ASK FOR HELP BECAUSE YOU'RE TOO STUPID
 
Top