> For the complete documentation index, see [llms.txt](https://docs.spadnext.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.spadnext.com/extending-and-apis/scripting-interface/c-scripting-provide-values.md).

# C# Scripting: Provide Values

```csharp
    /// <summary>
    /// A Demo for a script that provides some value(s) to SPAD.neXt
    /// reference Implementation. 
    /// </summary>
    public class ProvideValueDemoScript : ScriptStub
    {
        protected override string ScriptDataPrefix => "DEMO";

        protected override void InitializeScript()
        {
            ScriptLogger.Info("In Init");
            FlightStarted += OnFlightStarted;
            FlightEnded += OnFlightEnded;
            RegisterData();
            workerTask = Task.Run(workerThreadAction, CancelToken);
        }

      

        protected override void DeinitializeScript()
        {
            // Signal to end worker Task is set by base class via the CancelToken already
            // Wait for worker task to gracefully end
            Task.WaitAll(workerTask);
        }

        private bool isFlightStarted = false;
        private Task workerTask = null;
        

        private void RegisterData()
        {
            // Register all the Data's this script provides
            GetOrCreateScriptDataValue("CYCLE"); // => LOCAL:DEMO_CYCLE
        }

        /// <summary>
        /// Increment LOCAL:DEMO_CYCLE by 1 every 1 second
        /// </summary>
        private async Task workerThreadAction()
        {
            while (!CancelToken.IsCancellationRequested)
            {
                if (isFlightStarted)
                {
                    SetScriptDataValue("CYCLE", GetScriptDataValue<int>("CYCLE") + 1);
                }
                await Task.Delay(1000);
            }
        }

        private void OnFlightStarted(ISimulationInterface sender, IAircraft aircraft)
        {
            ScriptLogger.Info($"FlightStarted: {aircraft?.Name} ({sender.SimulationGamestate})");
            isFlightStarted = true;
        }

        private void OnFlightEnded(ISimulationInterface sender, SimulationGamestate newState)
        {
            if (isFlightStarted && newState != SimulationGamestate.Flying)
            {
                ScriptLogger.Info($"Flight end. ({newState})");
                isFlightStarted = false;
                
                SetScriptDataValue("CYCLE", 0);
            }
        }
    }
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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.spadnext.com/extending-and-apis/scripting-interface/c-scripting-provide-values.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.
