Identifier 'o' not found?

BlitzMax Forums/BlitzMax Beginners Area/Identifier 'o' not found?

How can I fixed it the "Identifier 'o' not found" (there is clue down blow with the code showing ' << Error) that need to be fixed please.

SuperStrict

Global GameObjectList:TList=CreateList()

' -----------------------TYPES-----------------------------
Type TGameObject
     Field X:Int = 320
     Field Y:Int = 420
     Field Speed:Int=3
     Field Image:TImage

     Method DrawSelf()
         DrawImage Image,X,Y
     End Method    

     Method UpdateState() Abstract
End Type 


Type ShipType Extends TGameObject
     Field  X:Int,Y:Int            'For Player
     Field  Image:TImage
     Field  Speed:Int =5           'Speed for Player

     Function Create:ShipType(File:String,xstart:Int,ystart:Int)
        Local Ship:ShipType = New ShipType
        Ship.X=xstart
        Ship.Y=ystart
        Ship.Image=LoadImage(file)
        If Ship.Image=Null
           Print "Not able to load image file. Program aborting"
           End
        EndIf
        ListAddLast GameObjectList, Ship
        Return Ship
     End Function

     Method Draw()
            DrawImage Image,X,Y
     End Method

     Method Move()
            If KeyDown(Key_Right) Then X:+Speed
            If KeyDown(Key_Left)  Then X:-Speed
           'If KeyDown(Key_Up)    Then Y:-Speed
           'If KeyDown(Key_Down)  Then Y:+Speed

            ' Collisions for Wall on each side to stop
            ' Player going off the playing area!
            If X<0   Then X=0
            If X>770 Then X=770
     End Method
End Type


Type TAlienShip Extends TGameObject
     Field X:Int = 320
     Field Y:Int = 0
     Field Speed:Int=3
     Field Image:TImage

     Function Create:TAlienShip(File:String,xstart:Int,ystart:Int)
         Local Alien:TAlienShip=New TAlienShip
         Alien.X=xstart
         Alien.Y=ystart
         Alien.Image=LoadImage(LoadBank(File))

         If Alien.Image=Null
            Print "Not able to load image file. Program aborting 2"
            End
         EndIf

         ListAddLast GameObjectList,Alien
         Return Alien
    End Function

    Method UpdateState()
        X :- Speed
        If X<-ImageWidth(Image) Then X=620
    End Method

    Method DrawSelf()
        DrawImage Image,X,Y
    End Method    

End Type

Local myShip:ShipType  = ShipType.Create("gfx/blobship.png",400,500)
Local Alien:TAlienShip = TAlienShip.Create("Gfx/cartoonufo_1-1.png",320,0)

' ---------------SETUP GAME CONDITION---------------
Graphics 800, 600, 0
HideMouse

' ---------------------MAIN LOOP-------------------------
While Not KeyDown(Key_Escape)
      Cls
      For o:TGameObject=EachIn GameObjectList ' << Error
          o.DrawSelf()
          o.UpdateState()
      Next
      Flip
Wend


You're using SuperStrict and haven't defined what O is. You must do this before using it.

Like GfK said:
For local o:TGameObject=EachIn GameObjectList '

For local o:TGameObject=EachIn GameObjectList '

You cant do that as it is cause the error and I even try this

local o:TGameObject=EachIn GameObjectList '

or this

local o:TGameObject

both of them is Error!

That changes works for me with the code posted but it does cause another, unrelated, error.

it does cause another, unrelated, error.


What error did you get please?

Your error was not overloading the Abstract method 'UpdateState' in your extended TShipType type.

Fixed (added UpdateState() in your TShipType type - and the For Local fix):
SuperStrict

Global GameObjectList:TList=CreateList()

' -----------------------TYPES-----------------------------
Type TGameObject
     Field X:Int = 320
     Field Y:Int = 420
     Field Speed:Int=3
     Field Image:TImage

     Method DrawSelf()
         DrawImage Image,X,Y
     End Method    

     Method UpdateState() Abstract
End Type 


Type ShipType Extends TGameObject
     Field  X:Int,Y:Int            'For Player
     Field  Image:TImage
     Field  Speed:Int =5           'Speed for Player

     Function Create:ShipType(File:String,xstart:Int,ystart:Int)
        Local Ship:ShipType = New ShipType
        Ship.X=xstart
        Ship.Y=ystart
        Ship.Image=LoadImage(file)
        If Ship.Image=Null
           Print "Not able to load image file. Program aborting"
           End
        EndIf
        ListAddLast GameObjectList, Ship
        Return Ship
     End Function

     Method Draw()
            DrawImage Image,X,Y
     End Method

     Method Move()
            If KeyDown(Key_Right) Then X:+Speed
            If KeyDown(Key_Left)  Then X:-Speed
           'If KeyDown(Key_Up)    Then Y:-Speed
           'If KeyDown(Key_Down)  Then Y:+Speed

            ' Collisions for Wall on each side to stop
            ' Player going off the playing area!
            If X<0   Then X=0
            If X>770 Then X=770
     End Method
	
	Method UpdateState()
		'Add your code here!
	End Method
End Type


Type TAlienShip Extends TGameObject
     Field X:Int = 320
     Field Y:Int = 0
     Field Speed:Int=3
     Field Image:TImage

     Function Create:TAlienShip(File:String,xstart:Int,ystart:Int)
         Local Alien:TAlienShip=New TAlienShip
         Alien.X=xstart
         Alien.Y=ystart
         Alien.Image=LoadImage(LoadBank(File))

         If Alien.Image=Null
            Print "Not able to load image file. Program aborting 2"
            End
         EndIf

         ListAddLast GameObjectList,Alien
         Return Alien
    End Function

    Method UpdateState()
        X :- Speed
        If X<-ImageWidth(Image) Then X=620
    End Method

    Method DrawSelf()
        DrawImage Image,X,Y
    End Method    

End Type

Local myShip:ShipType  = ShipType.Create("gfx/blobship.png",400,500)
Local Alien:TAlienShip = TAlienShip.Create("Gfx/cartoonufo_1-1.png",320,0)

' ---------------SETUP GAME CONDITION---------------
Graphics 800, 600, 0
HideMouse

' ---------------------MAIN LOOP-------------------------
While Not KeyDown(Key_Escape)
      Cls
      For Local o:TGameObject=EachIn GameObjectList
          o.DrawSelf()
          o.UpdateState()
      Next
      Flip
Wend


You should import brl.pngloader since you are loading png's, remember this for all other image formats (brl.jpegloader, brl.bmploader, etc)
You should also have your object list as a global inside the type TGameObject/TShipType.
Usually we can assume that when you declare a type, that it is a type (lol), so 'Type' at the end of your ship type is unnecessary.

What error did you get please?

Interesting way of doing things. So I'd now be reporting your problem to you? Thankfully Plash got there first.

thank you Plash and to everyone as well.. :)