Associative arrays
BlitzMax Forums/BlitzMax Programming/Associative arrays
| ||
Hi! Does Blitzmax have associative arrays? I would like to use those for several purposes, most important being localization, e.g: messages["file_not_found_error"] = "Sorry, the file could not be found" I tried using a TList approach but it's both too much typing and too much searching/re-iterating (slow). Thanks! |
| ||
No, but you can use a TMap...SuperStrict Framework brl.standardio Import brl.map Global messages:TMap = new TMap messages.Insert("file_not_found_error", "Sorry, the file could not be found") Print String(messages.ValueForKey("file_not_found_error")) Print Message("file_not_found_error") ' wrap stuff away in a Function/Method Function Message:String(key:String) Return String(messages.ValueForKey(key)) End Function |
| ||
Just in case you weren't aware, there's a few free localization modules available for Blitzmax that already implement automatic string substitution for localization, such as bah.locale, duct.locale or matibee.mbmframework |
| ||
Ah, TMap looks exactly like what I was looking for - many thanks! Edit: I will also look into the localization - thanks as well :) |
| ||
I never used TMap Always using TList.. Maybe I need to revise my methods. |
| ||
TMaps are great in that they're basically a hash but don't have collisions and lookup, inset and delete are all O(log n). |