Identifier 'o' not found?

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

Hotshot2005(Posted 2008) [#1]
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



GfK(Posted 2008) [#2]
You're using SuperStrict and haven't defined what O is. You must do this before using it.


Volker(Posted 2008) [#3]
Like GfK said:
For local o:TGameObject=EachIn GameObjectList '


Hotshot2005(Posted 2008) [#4]
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!


tonyg(Posted 2008) [#5]
That changes works for me with the code posted but it does cause another, unrelated, error.


Hotshot2005(Posted 2008) [#6]
it does cause another, unrelated, error.


What error did you get please?


plash(Posted 2008) [#7]
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):


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.


tonyg(Posted 2008) [#8]
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.


Hotshot2005(Posted 2008) [#9]
thank you Plash and to everyone as well.. :)