> For the complete documentation index, see [llms.txt](https://guide.cronuszen.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://guide.cronuszen.com/gpcscripting/gpc-script-guide/inputs-and-outputs/toggle-state-without-repeat-firing.md).

# Toggle state without repeat firing

Do not toggle from a held-value check; it would flip on every cycle:

### Why this matters

`get_val` returns a value every single VM cycle. If you toggle based on whether a button is currently held down, your toggle flips on every cycle the button is pressed — which means dozens of flips per second. From the outside it looks random: sometimes the toggle ends up on, sometimes off, depending on exactly when you release the button.

The fix is to only toggle when the button is **first pressed**, not while it stays held.

***

### The wrong way

Do not toggle from a held-value check; it would flip on every cycle:

```c
int enabled;

main {
    if(get_val(PS5_CROSS)) {
        enabled = !enabled;
    }
}
```

Every cycle where CROSS is held, `enabled` flips. Hold CROSS for half a second and you get an unpredictable final state.

### The right way

Use `event_press`, which is only true on the exact cycle the button changes from released to pressed:

```c
int enabled;

main {
    if(event_press(PS5_CROSS)) {
        enabled = !enabled;
    }
}
```

Now one press equals one toggle, no matter how long CROSS is held.

***

### Quick rule

* `get_val` → **is** the button pressed right now?
* `event_press` → **did** the button just get pressed this cycle?

Use `get_val` when you want continuous action while a button is held. Use `event_press` when you want a one-shot reaction to a press.


---

# 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, and the optional `goal` query parameter:

```
GET https://guide.cronuszen.com/gpcscripting/gpc-script-guide/inputs-and-outputs/toggle-state-without-repeat-firing.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
