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

GameMaker [SOLVED] How to check if a ds_map is something

B

Bokkie2988

Guest
Hello,

I have a question, how do I check if a ds_map is, for example, 1?

I currently have this:
Code:
if (weapons == [1]){
}
but it doesn't seem to work. Can anyone help me?
 

johnwo

Member
It's kind of unclear what you want to do here...
If it's checking if an element of a ds_map is a certain value, you could either do:
Code:
if (map[? key] == value)
or iterate through the keys, as such:
Code:
var key = ds_map_find_first(map);
for (var i=0;i<ds_map_size(map);i++){
    if (map[? key] == value) {
        // Found value, break loop
        break;
    }
    // Get next key
    key = ds_map_find_next(map, key);
}
 
B

Bokkie2988

Guest
It's kind of unclear what you want to do here...
If it's checking if an element of a ds_map is a certain value, you could either do:
Code:
if (map[? key] == value)
or iterate through the keys, as such:
Code:
var key = ds_map_find_first(map);
for (var i=0;i<ds_map_size(map);i++){
    if (map[? key] == value) {
        // Found value, break loop
        break;
    }
    // Get next key
    key = ds_map_find_next(map, key);
}
Thank you. I actually meant the first thing.
 
Top