Game Development Reference
In-Depth Information
When the console fills with more than one error, the errors are typically listed in the
order in which they were detected by the compiler, that is, from top to bottom. It's
considered best practice to tackle errors in order, because earlier errors can cause
later ones. Thus, resolving earlier errors can, potentially, resolve later ones. To
resolve an error, start by double-clicking on the error from the Console window, and
MonoDevelop will open automatically, highlighting the line where the error itself was
found or where the error was first detected. It is important to note that MonoDevelop
will take you to the line where the error was first detected, although resolving the error
will not always involve editing that line specifically. Depending on the issue, you will
need to change to a different line than theone highlighted. If you double-click on the
top error (first error) in Console , as generated by the code sample 2-1, MonoDevelop
will open and highlight line 11. You can fix this error in two ways: either by renaming
mynumber to MyNumber in line 11 or by renaming the variable MyNumber to mynumber in
line 6. Now, consider the following code sample 2-2:
01 using UnityEngine;
02 using System.Collections;
03
04 public class ErrorScript : MonoBehaviour
05 {
06 int MyNumber = 5;
07
08 // Use this for initialization
09 void Start () {
10
11 MyNumber = 7;
12 }
13
14 // Update is called once per frame
15 void Update () {
16 MyNumber = 10;
17 }
18 }
Code sample 2-2 fixes the errors in code sample 2-1. However, it leaves us with
a warning instead (as shown in the following screenshot). This indicates that the
variable MyNumber is never used. It's assigned a value in lines 11 and 16, but this
assignment is never of any ultimate consequence for the application. Here, this
warning could be ignored and the code would remain valid. Warnings should be
seen primarily as recommendations made by the compiler about your code. How
you handle them is ultimately your choice, but I recommend that you try to
eliminate both errors and warnings wherever practical.
 
Search WWH ::




Custom Search