title: Basic Racket: End Values
body: <p>I'm taking an intro programming class. We use the student languages in DrRacket.</p>
  
  <p>Problem: I would like to return a certain value at the end of a big-bang game (require 2htdp/universe)`.</p>
  
  <p>Current Output: When the game ends, DrRacket returns my current worldstate, which is a list of structures that I use in the game.</p>
  
  <p>Progress towards solution: It seems like <code>stop-with</code> may be able to help me, but I'm not sure how to use it.</p>
  
  <p>TL;DR: <br> 
  Problem: Game Ends --> Returns World State (List of Structures) <br>
  Want: Game Ends --> Return Other Value (Number)</p>
  
  <p>Let me know if I can clarify in any way! Thanks!</p>
  
  <p>EDIT: I think I found the solution. I use the expression that I usually call for my end? function and put it instead as a cond branch in my on-tick function. When that function is called in my on-tick function, then it changes the world-state to whatever I want to output. Then, in my end? function, I just check to see whether the worldstate is something different than it usually is.</p>
  
  <p>Thanks for the help!</p>
  
  <p>Solution: </p>
  
  <pre><code>; A Test Case (TC) is a (make-tc Number)
  (define-struct tc [number ticks])
  ; number is a number used to test this problem
  
  ; TC -&gt; Number
  ; Begins the main big-bang function; outputs the inverse of tick speed
  ; times the number of ticks elapsed when the game ends. 
  (define (main tick-speed)
     ( * (/ 1 tick-speed) 
          (tc-ticks (big-bang (make-tc 0 0)
             [to-draw draw]
             [on-tick check tick-speed]
             [stop-when end? end-scene]))))
  </code></pre>