the "!" operator and maps

I realize the "!" operator is for boolean expressions, but is there a similar way to do the same thing with map contents? Like a "if map does not contain" option.

for example:
Code:
if(!my_map contains xyz)
{ ...do this... }

I'm currently using:

Code:
if(my_map contains xyz){}
else{ ...do this... }

but it's not that pretty and I'm trying to clean up my code a little. Any suggestions?
 
I have another question reguarding maps. How can I use the contains operator on maps with multiple keys of a different datatype?

I'm using a map in the format:
Code:
int[string,item] my_map;

The problem I'm having is after I populate the map I can use contains to tell me if it has a specific string. This works fine:
Code:
if(my_map contains "teststring")
	print("teststring accounted for!","blue");

but if I try the same thing with an item it doesn't like it:
Code:
if(my_map contains $item[xyz])
	print("It contains xyz!");

I get the following error:
"Cannot apply operator contains to my_map (int [string, item]) and xyz (item)"

I'm not exactly sure how to iterate over a map in that format to check if it contains a specific item?
 

jasonharper

Developer
'contains' only considers the first dimension of the map. To apply it to the 2nd or later dimension, you have to iterate over the previous dimensions yourself:
Code:
int[string, item] my_map;

foreach stringKey in my_map {
    int[item] subMap = my_map[stringKey];
    if (subMap contains $item[xyz]) {
        print("found it");
    }
}
Basically, if you want to efficiently look for items in your map, you should make it the first key. If you need to look for both the strings and items, consider maintaining two copies of the map, one as int[string,item] and the other as int[item,string].
 
Top