# Logic Debugging

Debugging in **Incari** allows the user to follow the path of their **Logic's** execution. This not only connects **Incari Studio** with **Incari Player** in a visual way, but can show all evaluated values as each **Node** is stepped through.

### Debug Simulation

To enter **Debug Simulation**, simply locate the icon at the top of the **Logic Editor**. The image below references this with the green square. It is to the left of the normal **Play** icon, which would simply start the simulation and open the **Player** without providing the debugging features.

![Debug Simulation Icon.](https://1553081948-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU990HLHWA30dTfELtDUK%2Fuploads%2Fgit-blob-6fe0e416da6325543cc37a331486de65bb20e5e1%2Flogicdebugging1.png?alt=media)

#### Debug Toolbar

Once **Debug Simulation** has been selected, a new toolbar will appear. This is the **Debug Toolbar** and it has several useful icons which allow the user to maximize their debugging experience in **Incari**.

![Debug Toolbar.](https://1553081948-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU990HLHWA30dTfELtDUK%2Fuploads%2Fgit-blob-e348145f03d0a45c2ee75d9d8e01b12ea34a8319%2Fdebugtoolbar.png?alt=media)

The icons from left to right are: `Pause/Resume Simulation`, `Call next node`, `Step into a function or prefab`, `Step out of a function or prefab`, and `Focus on error`.

* `Pause/Resume Simulation` allows the user to pause and play the debugging visualization.
* `Call next node` is very useful. When the simulation has been paused in some way, or stopped by a [**Breakpoint**](#breakpoints), the user can use the `Call next node` to continue through the flow of execution. When a **Node** has been evaluated completely, a horizontal line will flash brightly beneath its name. When a **Node** is currently being inspected, a pale horizontal line will be displayed constantly.
* `Step into a function or prefab` can only be used on **Function** and **Prefab** **Nodes**. This lets the user access the **Function** or **Prefab** **Logic** represented by their **Nodes** in the **Scene Logic**. The debugging simulation will continue in a separate tab of the **Logic Editor** and the user can inspect any issues related to **Functions** or **Prefabs**.
* `Step out of a function or prefab` exits the **Function** or **Prefab Logic** during the debugging simulation and returns to the **Scene Logic**.
* `Focus on error` highlights the error by navigating to the broken **Node** and centering it in the **Logic Editor's** view.

With these features, the user has heightened control over the debugging process.

#### Flow of Execution

![Example Flow.](https://1553081948-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU990HLHWA30dTfELtDUK%2Fuploads%2Fgit-blob-9be12c9804aa5fce1726c270029ed46fcf3dedec%2Fexampleflow.gif?alt=media)

The user can see the flow of the debugging simulation by following the dot that passes along the connections between **Nodes**. This can be controlled with the processes maintained by the **Debug Toolbar**, which are described in the section above.

**Breakpoints**

![Adding and Removing a Breakpoint.](https://1553081948-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU990HLHWA30dTfELtDUK%2Fuploads%2Fgit-blob-f0810abb7106cf0166ba7cfe1ab72ff97bd0fda0%2Fsetbreakpointreal.gif?alt=media)

The flow can be manually stopped by setting **Breakpoints**. Simply right-click the **Node** that the flow of execution should be stopped at (i.e., will not continue into or past this **Node**), and select `Set Breakpoint`. This will add a red triangle just before the start of the **Node**. Alternatively, it can also be removed by doing the same thing once a **Breakpoint** has been set, and selecting `Remove Breakpoint`.

**Show Values**

![Show Values Example.](https://1553081948-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU990HLHWA30dTfELtDUK%2Fuploads%2Fgit-blob-ba506b08080037c84a5bf7d7a6411337cf338169%2Fshowvalues.gif?alt=media)

In **Debug Simulation**, it is possible to have a **Node's** values displayed during the flow of execution. Please note that this is not possible outside of **Debug Simulation** and the values will only appear once that part of the **Node** has been evaluated. This means that output values will only show once the flow is ready to move onto the next **Node**.

**Example with Stepping into and out of a Function**

To better understand the possibilities of the **Debug Simulation**, an example incorporating a **Function** is displayed below:

![Debug Simulation Example with Function.](https://1553081948-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FU990HLHWA30dTfELtDUK%2Fuploads%2Fgit-blob-f254b66446d8f6a8cd93d850f56643b15d232565%2Fstepthroughexample.gif?alt=media)
