Forgot how to use methods (again).....
BlitzMax Forums/BlitzMax Programming/Forgot how to use methods (again).....
| ||
lol, I have forgotten how to use Types and Methods (for a third time). Can anyone please tell me what I am doing wrong in my code below?
Strict
AppTitle:String = " "
Graphics 800, 600
AutoMidHandle True
SeedRnd(MilliSecs())
Incbin "blue_paddle.jpg"
Global bpad:TImage = LoadImage("incbin::blue_paddle.jpg")
bpad.TPlayerStick = New TPlayerStick
While Not AppTerminate() Or KeyDown(KEY_ESCAPE)
Cls
bpad.TPlayerMove
Flip(-1)
Wend
Type TPlayerStick
Field X:Int = 400
Field Y:Int = 300
Method TPlayerMove()
If KeyDown(KEY_LSHIFT)
Y = Y + 1
ElseIf KeyDown(KEY_RCONTROL)
Y = Y - 1
EndIf
EndMethod
EndType
Many thanks for your help in advance! :D |
| ||
this is where your problem is:
' you need to declare a variable for the image that is different than the variable for the object Tplayer
Global bpad:TImage = LoadImage("incbin::blue_paddle.jpg")
'when using strict you have to declare the variable as local or global
bpad.TPlayerStick = New TPlayerStick
it should be something like this:
Global dpadImage:TImage = LoadImage("incbin::blue_paddle.jpg")
Local bpad:TPlayerStick = New TPlayerStick
|
| ||
| I still dont quite understand. it says this: Compile Error: Expression must be a variable and highlights this line: Local bpad.TPlayerStick = New TPlayerStick Here is the code I used to compile in BLide Strict
AppTitle:String = " "
Graphics 800, 600
AutoMidHandle True
SeedRnd(MilliSecs())
Incbin "blue_paddle.jpg"
Global bpadImage:TImage = LoadImage("incbin::blue_paddle.jpg")
Local bpad:TPlayerStick = New TPlayerStick
While Not AppTerminate() And Not KeyDown(KEY_ESCAPE)
Cls
bpad.TPlayerMove
Flip(-1)
Wend
Type TPlayerStick
Field X:Int = 400
Field Y:Int = 300
Method TPlayerMove()
If KeyDown(KEY_LSHIFT)
Y = Y + 1
ElseIf KeyDown(KEY_RCONTROL)
Y = Y - 1
EndIf
EndMethod
EndType
Am I doing something else incorrectly? What does it mean to add an Expression as a Variable? EDIT: hmm... I just know i have forgotten to add something here but am not sure what it was.... :/ Last edited 2012 Last edited 2012 |
| ||
Local bpad.TPlayerStick = New TPlayerStick thats not what I posted. LOL, you are getting the Blitz3d syntax mangled with Blitzmax . "." should be ":". |
| ||
| you are getting the Blitz3d syntax mangled with Blitzmax I guess I should just keep going with BlitzMax and leave B3D alone for now, Using 2 languages at once can really throw you off! :D |
| ||
Global bpad:TImage = LoadImage("incbin::blue_paddle.jpg")
bpad.TPlayerStick = New TPlayerStick...will never work, since there is no TPlayerStick field defined in a TImage, obviously. You need to declare things separately, like so: Global bpadImage:TImage = LoadImage("incbin::blue_paddle.jpg")
Global bpad:TPlayerStick = New TPlayerStickLast edited 2012 |
| ||
I get "." and ":" confused all the time and what is the difference betweenGlobal bpadImage:TImage = LoadImage("incbin::blue_paddle.jpg")and Global bpad:TImage = LoadImage("incbin::blue_paddle.jpg")Why does this matter? |
| ||
| you declared "bpad" as variable of type "Image" and as a variable of type "TPlayerStick" you have to decide for one or the other. variables can not be used for two different uses. Last edited 2012 |
| ||
| "." is the separator used to "talk" to an object. ":" is the separator the declares what kind of object a variable is assigned to. I get "." and ":" confused all the time and what is the difference between Global bpadImage:TImage = LoadImage("incbin::blue_paddle.jpg")and Global bpad:TImage = LoadImage("incbin::blue_paddle.jpg") There is no difference between those, they are both valid. However a variable can only be used for one object - you could not use bpad (or bpadImage) for anything other than TImage object operations. It's different when you use Local variables within methods or loops. A variable of the same name can then be very well used for all kinds of objects, provided those Local variables are in separate methods. Last edited 2012 |