Some newb questions

BlitzMax Forums/BlitzMax Beginners Area/Some newb questions

xcessive(Posted 2009) [#1]
There are a few small things about the language that im very confused about and hope somebody can explain to me.

1. Is it possible to use a string variable as the name of a parameter? for example if i wanted to create a new instance of a type i made...

Type thing
field x:string
field y:int
end type

reference:string = "newvar"
newvar:thing = new thing
reference.x = 1

is it possible to have this code set newvar's value to one, using the other variable as a sort of reference to it?

2. How do i use lists and what are they? are they like arrays :s im very confused.


Brucey(Posted 2009) [#2]
1) Not directly, but using Reflection you can create an instance of an object using its name.
I don't have an example handy.

2). A TList is a doubly-linked list. It is really just a normal Type with list functionality :
SuperStrict

Local myList:TList = New TList

myList.AddLast("World")
myList.AddFirst("Hello")

Print "Size = " + myList.Count()

For Local text:String = EachIn myList
	Print text
Next

myList.Clear()

Print "Size = " + myList.Count()

Because it is a doubly-linked list, each node contains, as well as the next-node link, a second link field pointing to the previous node in the sequence. The two links may be called forward(s) and backwards.
You can access the internal links if you need more fine-grained access, but most of the time you can use the basic methods of the TList.

There's also a procedural set of functions for TList if you prefer coding like that :
myList = CreateList()

ListAddLast(myList, "Hello")


Each to their own, of course.


xcessive(Posted 2009) [#3]
Thanks that was helpfull!