need help with casting array from list to object

BlitzMax Forums/BlitzMax Beginners Area/need help with casting array from list to object

MaximilianPs(Posted 2008) [#1]
i've an object called tPlanet
this object have some different field that like stings floats and intgers...

to fill all this fields i've used a realy long string that will come from a webpage.
with a function i've filled a list with the variables, and then i've converted the list in array.
ok...
now there is the code:
(save it where you have your MiniB3D example, should works.. but maybe not)
Import "../MiniB3D.bmx"
Strict
Local width=640,height=480,depth=16,mode=0
Graphics3D width,height,depth,mode

Local cam:TCamera=CreateCamera()
Local light:TLight=CreateLight()

Global planets:TList New TList

ListAddLast(planets, "PlanetA")
ListAddLast(planets, "Plutone")
ListAddLast(planets, "1")
ListAddLast(planets, "250") 
ListAddLast(planets, "400") 
ListAddLast(planets, "PlanetB")
ListAddLast(planets, "Jupiter") 
ListAddLast(planets, "2")
ListAddLast(planets, "300") 
ListAddLast(planets, "500") 

Type TSolSys
	Field Id:Int
	Field Name:String
	Field totPlanet:Int
	
	Method CreateSystem()
		Local plntMesh:TMesh[]
		Local pianeta:tPlanet[]
		Local sysArr:Object[] = ListToArray(planets)
		Local i:Int , plntCntr:Int = 0
		
		For i = 0 To sysArr.length - 1
			If Left(String(sysArr[i]) , 6) = "Planet" Then
				myplanet= myplanet[0..plntCntr+ 1]
				myplanet[plntCntr] = New tPlanet
				myplanet[plntCntr].panetName = String(sysArr[i+ 1])
				myplanet[plntCntr].panetID = String(sysArr[i + 2]).toInt
				myplanet[plntCntr].posX = String(sysArr[i + 3]).toFloat
				myplanet[plntCntr].posY = String(sysArr[i + 4]).toFloat
				
				plntMesh = plntMesh[0..cntPlnt+1]
				plntMesh[plntCntr] = CreateSphere()
				PositionEntity plntMesh[plntCntr], myplanet[plntCntr].posX, myplanet[plntCntr].posY
			End If 
		Next
	End Method
End Type

Type TPlanet ' Extends TSolSys
	Field panetID:Int
	Field panetName:String
	Field posX:Float
	Field posY:Float
End Type

' used by camera code
Local mxs#=0
Local mys#=0
Local move#=0.5
MouseXSpeed() ' flush
MouseYSpeed() ' flush

Local SistemaSolare:tSolSys = New tSolSys
SistemaSolare.createSystem()

While Not KeyDown(KEY_ESCAPE)		

	' control camera mouse look
	mxs#=mxs#+(MouseXSpeed()/5.0)
	mys#=mys#+(MouseYSpeed()/5.0)

	RotateEntity cam,mys#,-mxs#,0

	MoveMouse width/2,height/2
	MouseXSpeed() ' flush
	MouseYSpeed() ' flush

	' move camera forwards/backwards/left/right with cursor keys
	
	If KeyDown(KEY_UP)=True Then MoveEntity cam,0,0,move# ' move camera forward
	If KeyDown(KEY_DOWN)=True Then MoveEntity cam,0,0,-move# ' move camera back

	If KeyDown(KEY_LEFT)=True Then MoveEntity cam,-move#,0,0 ' move camera left
	If KeyDown(KEY_RIGHT)=True Then MoveEntity cam,move#,0,0 ' move camera right

	RenderWorld
	Flip
Wend
End


the error that i've got is "unable to convert from int() to int"
on this line
pianeta[plntCntr].panetID = String(sysArr[i + 2]).toInt


i've lost a pair of days testing and studing the casting but looks that i can't solve it by my self :(


Azathoth(Posted 2008) [#2]
toInt() is a method, you should be calling it like one.


MaximilianPs(Posted 2008) [#3]
you mean something like
Int(string(sysArr[i+2]))


lol.. damned VB :-X


Azathoth(Posted 2008) [#4]
Actually I meant
String(sysArr[i + 2]).toInt()
But you can use Int() instead.