Associative arrays

BlitzMax Forums/BlitzMax Programming/Associative arrays

Cocopino(Posted 2015) [#1]
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!


Brucey(Posted 2015) [#2]
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



xlsior(Posted 2015) [#3]
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


Cocopino(Posted 2015) [#4]
Ah, TMap looks exactly like what I was looking for - many thanks!

Edit: I will also look into the localization - thanks as well :)


Hardcoal(Posted 2015) [#5]
I never used TMap

Always using TList..

Maybe I need to revise my methods.


GW(Posted 2015) [#6]
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).