I think tonyg misssed this out:
To make a new player, do this
Don't forget that = New TCard[5] sets up an array, but doesn't set up the cards inside. You need to to this seperately. If you don't know how I can tell you.
A create function like this is useful because you can add some parameters for your new object. Here's a make believe example:
So this lets you set up players with any number of cards. Nifty eh?
PS Your original code didn't compile because of the unneeded []
Type TPlayer Field playerHand:TCard[] Function Create:TPlayer() 'instantiates a player Local temp:TPlayer = New TPlayer temp.playerHand = New TCard[5] Return temp End Function End Type
To make a new player, do this
main code blah blah Local aplayer:TPlayer = TPlayer.Create() aplayer.blahblahblah
Don't forget that = New TCard[5] sets up an array, but doesn't set up the cards inside. You need to to this seperately. If you don't know how I can tell you.
A create function like this is useful because you can add some parameters for your new object. Here's a make believe example:
Type TPlayer Field playerHand:TCard[] Function Create:TPlayer(numCards:Int) 'instantiates a player Local temp:TPlayer = New TPlayer temp.playerHand = New TCard[numCards] Return temp End Function End Type Local aplayer:TPlayer = TPlayer.Create(5) Local otherplayer:TPlayer = TPlayer.Create(4)
So this lets you set up players with any number of cards. Nifty eh?
PS Your original code didn't compile because of the unneeded []