Computer Science Canada Passing a flexible array of record as a parameter for a function |
Author: | Insectoid [ Fri Nov 07, 2008 7:38 pm ] | ||
Post subject: | Passing a flexible array of record as a parameter for a function | ||
I'm working on a blackjack program, and I am using a record to hold my cards (suit, value, and image) and storing the 'cards' in the player's 'hand', which is a flexible array. Now, I have created a function to count the total value of the cards in any player's hand, and am passing it the hand of the player who's hand is being counted. Unfortunately, this doesn't work. Is there a way around this? [part of] My code:
|
Author: | Clayton [ Fri Nov 07, 2008 8:07 pm ] |
Post subject: | RE:Passing a flexible array of record as a parameter for a function |
What you have does work, except for two little errors. One I'll give to you, the other I won't. You're missing a bracket in your if statement in the for loop in your function. Second, the bounds of the array being passed into the function must match exactly, with * being a wildcard, what's wrong with your parameter? |
Author: | Insectoid [ Fri Nov 07, 2008 8:18 pm ] |
Post subject: | RE:Passing a flexible array of record as a parameter for a function |
oops, that bracket was accidentally left over from when I was testing some other ways to do it. As for the *, I was following your tutorial (Arrays), which said that it would allow the function to accept an array of unknown length. Seeing as I have no idea how big these arrays will be, I figured this was the way to go. Clayton, for his array tutorial, wrote: We can modify our procedure so that it takes an array of unknown length. To do this, when declaring the parameters to our procedure, we replace the upper bound with an asterisk (*). |
Author: | Clayton [ Fri Nov 07, 2008 8:19 pm ] |
Post subject: | RE:Passing a flexible array of record as a parameter for a function |
The asterisk is correct, which leaves what wrong if the bounds must be exactly the same? |
Author: | Insectoid [ Fri Nov 07, 2008 8:21 pm ] |
Post subject: | RE:Passing a flexible array of record as a parameter for a function |
oh crap, forgot that the hand arrays start at one..most of the other ones start at 2 (because decks don't have a '1' card (aces are labeled 14)). Well, now I feel stupid... Thanks Clayton! |