Function doesn't recognise type

BlitzPlus Forums/BlitzPlus Beginners Area/Function doesn't recognise type

Roe(Posted 2005) [#1]
Hello,

just a quick one, how do I make my Functions recognise my types??

I've got this:


Type player
field x,y
end type

Player1.player = New player
Player1\X = centerx+gridsize
Player1\Y = (centery+gridsize) - spriteoffset

;--some lines later

If KeyDown = kleft Then
playermoveleft()
EndIf

;--further down


Function playermoveleft()

player1\x = player1\x - 1

End Function


It's saying "Variable must be a type"
What am I doing wrong now? :)

Sorry for being such a noob, and thanks again in advance for the quick responses from you pros!


Hip Teen(Posted 2005) [#2]
you must set player1.player as global, so just put
global player1.player
at the top and it will work


Blaine(Posted 2005) [#3]
Change it to this:
Fuction playermoveleft()

For player1.player = Each player
	player1\x = player1\x - 1
Next

End Function

And that should do it.

Of course, if you need to target a specific player, then this won't work. :(


Roe(Posted 2005) [#4]
cheers guys


Snarty(Posted 2005) [#5]
Function PlayerMoveLeft(aPlayer.Player)

	aPlayer\x = aPlayer\x - 1

End Function
This will work with any player, just pass the current player to the function.