Writing Code
In this article:
EventIDE provides a flexible and user-friendly programming environment that supports several coding languages: C# (default), Python, and Visual Basic. The platform is tailored for experimental control, favoring a clean and minimal coding approach centered on property interfaces rather than complex object-oriented structures.
C# for Writing Code in EventIDE
Among the supported languages, C# is highly recommended due to its performance, extensive documentation, and familiarity among developers. Despite its depth, C# can be easily picked up even by users without prior programming experience.

Why C# is Easy to Use in EventIDE
The syntax is similar to C and Java, making it intuitive and widely recognizable.
The language is extensively documented with abundant online resources and tutorials.
EventIDE eliminates the need for object-oriented knowledge, classes, or custom libraries.
All experiment functionality is exposed via object properties and proxy variables—there are no procedural APIs to memorize.
Code typically involves simple constructs: variable assignments, conditions, and loops.
As a result, most experiments can be programmed using straightforward logic within compact snippets of code.
Code Snippets and Event-Driven Model
In contrast to traditional procedural programming, EventIDE follows an event-driven model. Rather than writing a monolithic program with a central control structure, you break your logic into small code snippets tied to specific phases of the experiment.
Each snippet is a mini-program executed in response to a particular runtime event—such as the onset of an event, a button press, or an update in stimulus intensity. Collectively, these snippets define the experimental logic without requiring a single, centralized loop.
Although the snippets are discrete, you can share data between them via:
Global variables, declared in the Header snippet.
Proxy variables, which provide access to EventIDE objects and their properties.
Global functions, which can be defined once and used across multiple snippets.

Snippet Types and Timing
Every code snippet in EventIDE is associated with a particular owner: the Experiment, an Event, or an Element. The timing and purpose of the snippet depend on its owner and location within the experimental flow.
The Snippets Panel at the bottom of the EventIDE window shows available snippets for the currently selected objects. It is organized as follows:
First row: Snippets of the Experiment object.
Second row: Snippets of the currently selected Event.
Subsequent rows: Snippets of all Elements contained within the selected Event.

The following table outlines the snippet types available and their respective roles:
Owner | Snippet Name | Purpose and Usage |
Experiment | Header | Used for declaring global variables and functions. Executed at compile time, not at runtime. |
Status Screen | Contains XAML markup for the runtime Status Screen, showing custom visualizations or diagnostics. | |
Start | Called once at the beginning of the experiment. Used for runtime initialization. | |
Control Loop | Executes continuously during the experiment. Suitable for background tasks and real-time monitoring. | |
End | Called once at the end of the experiment. Used for cleanup and result aggregation. | |
Event | Route Conditions | Contains Boolean logic for conditional flow routing. Continuously evaluated until true. |
Rendering | Called whenever the visual content of the event changes. Use for monitoring or signaling visual updates. | |
Before Onset | Executes right before an event appears on screen. Use for last-moment changes. Avoid for time-critical updates. | |
After Onset | Executes immediately after event onset. Preferred for accurate timing of synchronized actions. | |
Control Loop | Executes repeatedly while the event is active. Use for animations, polling, or custom frame updates. | |
Before Offset | Executes at the transition to the next event. Use with caution if precise onset timing is required. | |
Element | Triggered | Called asynchronously when the element detects a status change (e.g., input received). Available only for elements that support it. |
Accessing Snippets
To open a snippet:
Double-click its icon in the Snippets Panel.
The snippet will appear in the central Code Editor tab interface.
Working with the Code Editor
EventIDE includes a powerful built-in code editor with features such as:
Syntax highlighting
Error checking
Code completion, including suggestions for global and proxy variables
Tabbed interface for working with multiple snippets simultaneously
The code editor opens snippets as tabs above the Event Editor panel, making it easy to switch between different pieces of code during experiment design. All changes are saved automatically when a snippet tab is closed.

Best Practices and Important Notes
Avoid blocking code: Since code snippets temporarily pause the internal timing system, avoid using while loops or other blocking statements that delay snippet completion.
//Avoid this!
while (ElapsedTime < 5000) { }Proxy variable updates: Proxy values set in a snippet are only applied after the snippet finishes execution. Setting a proxy multiple times will only commit the last value.
Measure execution time: Execution durations of snippets can be found in the statistical properties of their parent events after a test run.
Reusable logic: For complex or reusable code (e.g., psychophysical algorithms), consider implementing a custom Element. This is more efficient and modular than duplicating snippets.
Debugging tools: During runtime, EventIDE provides:
A variable watcher to monitor and modify variable values live.
A snippet monitor to track execution and set breakpoints.
Custom output via Reporter variables or the Status Screen for real-time debugging.
