Create Object with name

BlitzMax Forums/BlitzMax Beginners Area/Create Object with name

Grovesy(Posted 2005) [#1]
Is it possible to create a new object and pass it a a name to use with the object. so something like this:

[CODE]
Type TSwitch Extends TObject

Global List:TList
Global Image:Timage

Function Create(name)
name:TSwitch = New TSwitch
If List = Null List = CreateList()
List.AddLast name
EndFunction

Method New()
X = 300
Y = 400
EndMethod

End Type[/CODE]

This don't work but its what im trying to achieve, do i have to state what type "name" is?

Cheers


tonyg(Posted 2005) [#2]
That should be Ok depending on the other code.
Obviously, the next create will use 'Name' again so it will point to the last object on the list.


bradford6(Posted 2005) [#3]
Global SwitchList:TList

Type TSwitch 
Field name:String

Function Create:Tswitch(this_ones_name:String)
	temp:TSwitch = New TSwitch 
	temp.name = this_ones_name
	If SwitchList = Null SwitchList = CreateList()
	Switchlist.AddLast temp
EndFunction

Method New()
X = 300
Y = 400
EndMethod

End Type

tswitch.create("mary")
tswitch.create("John")

For p:Tswitch = EachIn switchlist
	Print p.name
Next