Why Do I get this Error?
BlitzMax Forums/BlitzMax Beginners Area/Why Do I get this Error?
| ||
Graphics 1024,768 Global Rocks:TList = New TList Type ScreenObject Field X:Int Field Y:Int Field XV:Float Field YV:Float Field Rotation:Float Field RotationSpeed:Float Field Image:Timage Method Update() Abstract End Type Type Ship Extends ScreenObject Function Create:Ship(XX,YY) P:Ship = New Ship P.Image:Timage=LoadImage("PlayerShip.Bmp") SetImageHandle (p.Image,36,42) P.X=Rand(1000) P.Y=Rand(700) Return P End Function Method Update() SetRotation Self.Rotation DrawImage (Self.Image,Self.X,Self.Y) End Method End Type Type Rock Extends ScreenObject Function Create:Rock(XX,YY) R:Rock=New Rock R.X=Rand(1024) R.Y=Rand(768) R.Rotation=Rand(360) R.RotationSpeed=Rnd(5.0) R.Image:Timage=LoadImage("Asteriod.bmp") SetImageHandle (R.Image,64,64) ListAddLast Rocks,R Return R End Function Method Update() Local Asteroid:Rock For Asteroid=EachIn Rocks Asteroid.Rotation:+1 If Asteroid.Rotation>360 Then Asteroid.Rotation=0 SetRotation Asteroid.Rotation DrawImage (Asteroid.Image,Asteroid.X,Asteroid.Y) Next End Method End Type Player:Ship=Ship.Create(0,0) For tt=1 To 50 Rock.Create(10,10) Next Repeat Cls SetBlend(alphaBlend) Player.Update() Rock.Update() Flip Until KeyHit(Key_Escape) Identifier 'Update' Not Found... It happens at Rock.Update() What am I doing Wrong? Thanks, Eric |
| ||
You have to create a new object like - "R:Rock = New Rock"Graphics 1024,768 Global Rocks:TList = New TList Type ScreenObject Field X:Int Field Y:Int Field XV:Float Field YV:Float Field Rotation:Float Field RotationSpeed:Float Field Image:Timage Method Update() Abstract End Type Type Ship Extends ScreenObject Function Create:Ship(XX,YY) P:Ship = New Ship P.Image:Timage=LoadImage("PlayerShip.Bmp") SetImageHandle (p.Image,36,42) P.X=Rand(1000) P.Y=Rand(700) Return P End Function Method Update() SetRotation Self.Rotation DrawImage (Self.Image,Self.X,Self.Y) End Method End Type Type Rock Extends ScreenObject Function Create:Rock(XX,YY) R:Rock=New Rock R.X=Rand(1024) R.Y=Rand(768) R.Rotation=Rand(360) R.RotationSpeed=Rnd(5.0) R.Image:Timage=LoadImage("Asteriod.bmp") SetImageHandle (R.Image,64,64) ListAddLast Rocks,R Return R End Function Method Update() Local Asteroid:Rock For Asteroid=EachIn Rocks Asteroid.Rotation:+1 If Asteroid.Rotation>360 Then Asteroid.Rotation=0 SetRotation Asteroid.Rotation DrawImage (Asteroid.Image,Asteroid.X,Asteroid.Y) Next End Method End Type Player:Ship=Ship.Create(0,0) For tt=1 To 50 R:Rock = New Rock Rock.Create(10,10) Next Repeat Cls SetBlend(alphaBlend) Player.Update() R.Update() Flip Until KeyHit(Key_Escape) blitzbasic.com forurm tag "code /code" - include the brackets |
| ||
I have that line in my Create:Rock Function... I noticed that if I don't have Abstract Update() and change the Update Method in the Rock Type to a Function my code Runs. This OOP is very new to me. |
| ||
But if you put that in a function it will only be called within the function not out of it its similar to Local but your looking for Global. |
| ||
change the Update Method in the Rock Type to a Function my code Runs. That's because you are invoking update() on the Type in general, not a specific instance of said type (thus it's looking for a Function called Update, which you don't have).Methods belong to objects/instances, and can only be invoked with a suitable object handle. Functions belong to the entire type/class and is traditionally invoked like in your example. The "Abstract" keyword means that you would like a particular function or method to be part of a type interface, but that implementation will be different depending on which extended object/class you're dealing with (polymorphism). |
| ||
ok thanks...That helps alot... It's going to take me a little getting use to all of this new stuff...Just like "Types" in general when I first started with BlitzBasic (2d). Thanks for all of the input. |