Create dynamic variables/Strings
BlitzMax Forums/BlitzMax Beginners Area/Create dynamic variables/Strings
| ||
is it possible to create variables from withing the program as a scripting language? ${$name} = $data |
| ||
Yes. Scripting languages are just text. Also Blitzmax has builtin support for LUA-scripts. -Henri |
| ||
thanks, but I was hoping on a solution more direct than my thinking: I want the user to name and set variable themself so I know the Stringname$ and the datastring$ I want to save em so the user can get it later My best solution so far is: I put Stringname$ in a List/Array and the index to the location for the datastring$[index] the problem with this is to get a string I need to check all Stringname$ to get the index to the datastring$ If Stringname$[n] = "Size" Print "Size = " + datastring$[n] |
| ||
Use TMap. $name is key and $data is valueSuperStrict Local Map:TMap = New TMap map.Insert("Name","John") Map.Insert("Pet","Dog") Map.Insert("State","California") Print String(Map.ValueForKey("Name")) Print String(Map.ValueForKey("Pet")) Print String(Map.ValueForKey("State")) |
| ||
Would TMap Do ? Tmap stores objects (string are object too) like TList , but you can set an ID/key for each object in order to find any spesific object afterwards with this key. ID/key can be anything you desire (int or string. If Int then convert to string). Example of TMap: SuperStrict Local map:TMap = CreateMap() 'Insert some values Local data:TData data = New TData data.name = "Michael" data.rank = "Officer" data.personal_id = 3 MapInsert(map, String("one"),data ) data = New TData data.name = "John" data.rank = "Secretary" data.personal_id = 4 MapInsert(map, String("two"),data ) 'Search with id. When using custom types you need to tell compiler which type to expect (typecast) Local my_data:TData = TData(MapValueForKey(map, "one")) 'Check if value was returned If my_data Then Print my_data.name Print my_data.rank Print my_data.personal_id Else Print "No value found" EndIf 'Your own type Type TData Field name:String Field rank:String Field personal_id:Int End Type EDIT: Slow -Henri |
| ||
WOW Thanks both of you Print String(Map.ValueForKey("Name")) This I been looking for, for years, it's a dream come true You made me buy BlitzMAX, Monkey X is for another day.. |