Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's not the same. Variables prefixed with <code>$</code> are global, whereas unprefixed variables are local. So when you change the value of <code>$h1c</code>, you are changing the value of the same <code>$h1c</code> variable that you reference elsewhere in the program. However, when you change the value of <code>chips</code>, you're only changing the value of <code>chips</code> within the context of the <code>review</code> method. As soon as that method returns, the value of <code>chips</code> is lost.</p> <p>So the simplest solution would be to not even bother passing the arguments to that method and just have it read the values of the global variables directly. That's probably not the best solution though in terms of style. In fact, generally the use of global variables at all is considered bad practice.</p> <p>The other solution is to return the new value of the player's chips from the review method, like so:</p> <pre><code>def review(hand, chips, betamount) abc = valueofcards(hand) #player's hand value klm = valueofcards($handD) #dealer's hand value if abc == klm and abc &lt; 19 puts "You tied" chips = chips elsif abc &gt; 18 puts "You lost" chips = chips - betamount elsif abc &lt; 19 and klm &gt; 18 puts "You won" chips = chips + betamount elsif abc &lt; 19 and abc &gt; klm puts "You won" chips = chips + betamount elsif abc &lt; 19 and klm &lt; 19 and klm &gt; abc puts "You lost" chips = chips - betamount end return chips # See here end </code></pre> <p>Then, set the value of the player's chips from outside the method:</p> <pre><code>def pre_review(num) puts "Recap of that round" puts "First Hand:" $h1c = review($hand1, $h1c, $h1bet) # Like this muckcards(num) end </code></pre> <p>There's probably a lot more that could be done to fix up that program in terms of code quality and programming style, but I won't get in to that right now. Keep learning! ;-)</p>
 

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