Time for action – Stepping through the game

Once you have reached a breakpoint and examined variable values at that point, the next thing you will want to do is step forward in the application so you can watch the application change over time. There are several options available to you for stepping forward through the application depending on what your intentions are. The following screenshot shows these options: Step Over, Step Into, Step Out, Pause, and Detach Debugger:

Time for action – Stepping through the game
  1. Press the Step into icon so that the application will start.
  2. As you can see below, the application is paused at the breakpoint. The current line of execution is highlighted in yellow:
    Time for action – Stepping through the game

    As mentioned earlier, when the debugger is attached, you can get the value of any variable in your game. However, it would be cumbersome to have to constantly look for each individual variable, especially if there is a variable that we want to examine over time. You can accomplish this by setting up a watch for a variable of interest and observe its value as it changes.

  3. Create a new watch by selecting the Watch tab in MonoDevelop. Enter the word Screen into the Watch tab to have MonoDevelop open an autocomplete dialog showing all of the attributes of the Screen object:
    Time for action – Stepping through the game

    We can see here that Screen has a currentResolution attribute attached to it.

  4. Select currentResolution so that a watch is created for this variable. If the variable you've selected is an object, you will see a triangle to the left of it. Clicking on this triangle will display any attributes of the object as shown in the following screenshot:
    Time for action – Stepping through the game

Here we are able to see all of the attributes of the Screen.currentResolution object.

What just happened?

We have just stepped through our application using the attached debugger and added a watch so that we can observe a variable as it changes over time. Adding watches is a common way to examine variables as they change during the execution of the game. As you begin writing complex scripts, creating watches will help you determine whether or not the correct behaviors are happening at runtime.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.58.182.39