Annoying variable type error
BlitzPlus Forums/BlitzPlus Programming/Annoying variable type error
| ||
I'm making a scrolling shooter, and this annoying error message pops up when I try to run it, saying "variable must be a type." I dunno why it's doing this: I clearly set up the player type, and I believe I'm following all the proper syntax. Why, then, is this happening? PS: Sorry, I don't know how to designate my typing as a code section, so the code starts here: ;/////// INIT /////// ;set up the graphics Graphics 600,800 ;enable double buffering SetBuffer BackBuffer ;enable AutoMidHandle AutoMidHandle True ;set key constants Const KEY_ESC=1 ;escape Const KEY_LEFT=203 ;left Const KEY_RIGHT=205 ;right Const KEY_UP=200 ;up Const KEY_DOWN=208 ;down ;load the ship image playerImage = LoadImage("ship_idle.bmp") ;player type Type player Field x,y End Type ;create player player1.player = New player player\x = 400 player\y = 300 ;/////// MAIN LOOP /////// While Not KeyHit(KEY_ESC) ;clear screen Cls ;move left If KeyDown(KEY_LEFT) player\x = player\x - 5 EndIf ;move right If KeyDown(KEY_RIGHT) player\x = player\x + 5 EndIf ;move up If KeyDown(KEY_UP) player\y = player\y - 5 EndIf |
| ||
[code][/code] or [/codebox] Does the error not tell you which line? |
| ||
Yes, it does, assuming the cursor jumping to a specific line means so. It is: It's really confusing |
| ||
player1\x =400This is a common mistake to make, mistaking the type for the instance. And to avoid it, you will find that many many people will aways call there type TPlayer or TAlien etc. I go so far as all instances are called APlayer, AAlien or MyPlayer1, etc MyPlayer1.TPlayer = new TPlayer |
| ||
No, actually the complete three lines at fault are this:player.player = New player player\x = 400 player\y = 300 Looks just fine to me EDIT: I think I got it now: player1.player = New player player1\x = 400 player1\y = 300 working fine. Also, I reversed the resolution values (so it's wider than it is tall) and put () next to BackBuffer (otherwise it was giving me "invalid buffer handle") Thanks for your help :P |