Calling a variable by its name

BlitzMax Forums/BlitzMax Programming/Calling a variable by its name

Is something like the follow possible in some sort of way

Const Level_001:Int = 500

Local WantedVariable:String = "Level_001"

Local OutputVariable:Int = VariableValue(WantedVariable)

to which OutPutVariable would become 500, hopefully that makes enough sense.

ta!

In my opinion this make no sense, as you could simply doi like
this:
Const Level_001:Int = 500
Local OutputVariable:Int = Level_001

This was my first thought, but then I have got your idea behind this. You want to get your LevelInfo from a String, maybe you have const like Level_001, Level_002 etc.

Then this will maybe help you:

Type TLevelData
	Field ID:Int
	Field Difficulty:Int
	
	Function Create:TLevelData(ID:Int , Dif:Int)
		Local L:TLevelData = New TLevelData
		L.ID = ID
		L.Difficulty = Dif
		Return L
	End Function
	
	Method ToString:String()
		Return "Level : " + ID + " With Difficulty : " + Difficulty
	End Method
	
End Type

Local Map:TMap = New TMap 'Init a new balanced binary tree


'Inserting Keys with created Values as Leveldata
For Local I:Int = 0 To 99
	Map.Insert( ("Level_" + I) , TLevelData.Create(I , I * 500) )
Next

'Reading Randomly Level datas from the TMap

For Local I1:Int = 0 To 10
	Local Value:String = ("Level_" + Rand(0 , 99) )
	Local Level:TLevelData = TLevelData(MapValueForKey(Map,Value) ) ' Attention You need to cast the value back to TLevelData because MapValueForKey only returns an'Object'
	Print Level.ToString()
Next


yeah, sorry i probably should have explained myself a bit better, I have a level editor with input boxes it'd be cool if I could supply the name of a variable to get its value :)

Ill give that code a look, much appreciated!