Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do my functions not change the values of my outside variables?
    primarykey
    data
    text
    <p>I am using Xcode version 4.6. In an application for the iPhone and iPad I am making, I made a function called dealCard. Here it is:</p> <pre><code>- (void)dealCard : (UIImageView *)cardImage : (int)card : (int)suit : (BOOL)aceBool : (int) cardValue : (int)total { suit = arc4random() % 4; card = arc4random() % 13; if (suit == 0) { //set images if (suit == 1) { //set images } if (suit == 2) { //set images } if (suit == 3) { //set images } if (card &lt; 10 &amp;&amp; card != 0) { NSLog(@"Setting cardValue"); cardValue = card+1; } else if (card != 0) { NSLog(@"Setting cardValue"); cardValue = 10; } else { NSLog(@"Setting cardValue"); aceBool = YES; if (total + 11 &lt;= 21) { cardValue = 11; } else { cardValue = 1; } } total = total + cardValue; NSLog(@"Total = %d cardValue = %d",total,cardValue); NSLog(@"playerTotal = %d playerCard3Value = %d",playerTotal,playerCard3Value); } </code></pre> <p>Further down the page I put:</p> <pre><code>[self dealCard: playerCard3Image : playerCard3 : playerSuit3 : playerCard3ace : playerCard3Value : playerTotal]; </code></pre> <p>My problem is in the cardValue. The output says "Setting cardValue", and then the instance variable numbers are both right, but the other two are wrong. The playerTotal reads whatever the total was before this card was dealt, and the playerCard3Value reads 0. To give you some context, this function is called not when the first or second card is dealt, but when the third and on are. The first two are not handled in a function. Does anyone know why this is happening?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload