# Troubleshooting Chain Tactics Local Development

This section addresses common issues when developing with Chain Tactics, complementing the "Common Challenges" outlined in [Headless Client](/build-with-sovrun/chain-tactics/headless-client.md). Problems like sqlite build errors, indexing mismatches, or insufficient funds can arise, and the solutions below provide practical guidance [Chain Tactics Game Wiki](https://sovrun.notion.site/Chain-Tactics-Wiki-1617ef7904b28023b8d6d23291b1923e).

#### Common Issues

* Cannot build sqlite
  * Resolution: Make sure to install the correct version of npm to prevent any issues during installation.
* ArgumentOutOfRangeException, The application is showing the wrong data from an array/list
  * Resolution: Blockchain systems use 1-based indexing for their data structures, which differs from most game development environments like Unity and Unreal Engine that use 0-based indexing. This distinction is important to consider when integrating blockchain data into game logic, as it can result in indexing mismatches if not handled properly.
* How to know the last error?
  * Resolution: Make use of the method GetLastError() in the class CTServerContext.
* Insufficient funds
  * Resolution: Actions requiring frequent updates (e.g., player movement, health regeneration, or cooldown timers) can become costly and slow on-chain. Adopt a hybrid model; frequent updates managed off-chain, critical updates on-chain.
* Why is it taking too long to receive updates from the backend?
  * Resolution: Applying traditional real-time mechanics directly on-chain can result in delays due to transaction confirmation times. Consider adding mechanics designed to tolerate delays.
* Why are some of the methods still running after I stop the editor?
  * Resolution: In C# native, tasks stop when the application exits. In Unity, tasks may continue running even after the editor stops. Implement CancellationToken to manage async lifecycle.
* Why is my code not called? Why is it not running properly?
  * Resolution: Calling Unity-related APIs in an async background will cause errors or undefined behaviors. Consider using UnityMainThreadDispatcher or SynchronizationContext to switch back to the main thread if you want to handle Unity APIs.
* Error PlayerAlreadyInMatch when trying to find a new match
  * Resolution: The player is already in a match. Consider calling Leave() first.

Refer to this link for other possible issues:[ sovrun / tactics-war-sc packages / contracts / src / common / Errors.sol](https://github.com/sovrun/chain-tactics-server/blob/main/tactics-war-sc/packages/contracts/src/common/Errors.sol).

Debugging:

* Use GetLastError() in CTServerContext.
* Check Errors.sol on Bitbucket for error codes.

<br>

Reference Links:

* [Chain Tactics Game Wiki](https://sovrun.notion.site/Chain-Tactics-Wiki-1617ef7904b28023b8d6d23291b1923e)
* [Nethereum ](https://docs.nethereum.com/en/latest/getting-started/)
* [MUD Framework ](https://mud.dev/quickstart)
* [Chain Tactics Server & Smart Contracts Repo](https://github.com/sovrun/chain-tactics-server)
* [Chain Tactics Unity Client Repo](https://github.com/sovrun/chain-tactics-unity-client)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sovrun.org/build-with-sovrun/chain-tactics/getting-started-guides/troubleshooting-chain-tactics-local-development.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
