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