Map issue (coming from MonkeyX)
BlitzMax Forums/BlitzMax Beginners Area/Map issue (coming from MonkeyX)
| ||
Hi All After using MonkeyX for 4 years I have come back to Bmax and converting some useful stuff I developed in Monday but I've hit a snag with Maps. I want to create a Map with an Int Array Value Field data:TMap = CreateMap() data.Insert("dave",[12,45,23]) So that all works but I have issues when getting the data back, id do it as follows in MonkeyX Print data.ValueForKey("dave")[0] Print data.ValueForKey("dave")[1] Print data.ValueForKey("dave")[2] I've tried all sorts converting to string etc but cant seem to get it. |
| ||
BlitzMax doesn't support generics or whatever other modern typesystem feature Monkey has that is enabling the above to work. Collections (unless you make an element-specific version) store Objects only, and the results of a query therefore have to be manually downcast before non-Object operations will apply to them. e.g. works: Print Int[](data.ValueForKey("dave"))[0] Print Int[](data.ValueForKey("dave"))[1] Print Int[](data.ValueForKey("dave"))[2] (array types are the only parameterised type in Max, and they don't really count) Converting to string might be mentioned in a few places because (according to BRL-led convention) it's how one stores numeric primitives in a collection or passes them to a "generic" function in an Object array (i.e. substitute for autoboxing), c.f. BRL.Reflection. It wouldn't apply to this example since the element actually being stored in the map is already an Object. |
| ||
Ah perfect thanks, I'll remember that for other things too. |