I’m trying to use a simple swap function, but for some reason it won’t accept the array of custom objects as a parameter even though that’s what I specified when making the function. I made sure the array I put in is the correct type, but it isn’t working. I’m sure the fix is simple, perhaps I missed something when I set up the “Card” class, but I’ve tried searching it on Google and nothing helpful comes up. There wasn’t much code to cut out since I just started this, so I hope I didn’t leave too much in.
The problem is on line 29, the error message is
The function swap() expects parameters like: " swap(Card[], int, int)"
class Card {
boolean faceUp = true;
void flip() {
this.faceUp = !this.faceUp;
};
}
Card[] cards = new Card[5];
void setup() {
size( 256, 512 );
background(0);
for ( int i = 0; i < 5; i++ ) {
cards[i] = new Card();
}
}
void doFlip( int amt ) {
if ( amt % 2 == 0 ) {
for ( int i = 0; i < amt / 2; i++ ) {
swap( cards, cards[i], cards[amt - i] );
}
}
}
void swap( Card[] array, int a, int b ) {
Card temp = array[a];
array[a] = array[b];
array[b] = temp;
}