# How to get system state during event handling?

**URL:** https://discourse.julialang.org/t/how-to-get-system-state-during-event-handling/77994
**Category:** General Usage
**Tags:** events
**Created:** [March 16, 2022, 9:19pm UTC](https://discourse.julialang.org/t/how-to-get-system-state-during-event-handling/77994 "2022-03-16T21:19:41Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![egor](https://avatars.discourse-cdn.com/v4/letter/e/6de8d8/32.png) [@egor](https://discourse.julialang.org/u/egor)
#### Post date: [March 16, 2022, 9:19pm UTC](https://discourse.julialang.org/t/how-to-get-system-state-during-event-handling/77994/1 "2022-03-16T21:19:41Z")

</div>

Hello everyone, I’m going through an example from the documentation about event handling during dynamic system integration.

```julia
using DifferentialEquations
function f(du,u,p,t)
    du[1] = -u[1]
end
u0 = [10.0]
const V = 1
prob = ODEProblem(f,u0,(0.0,10.0))
sol = solve(prob,Tsit5())
Plots.plot(sol)

```

At a certain step (t = 4.0), I want to get the state of the system, for this I wrote the following code:

```julia
check = 0
condition(u,t,integrator) = t==4
function affect!(integrator)
    check = integrator.u[1]
end
cb = DiscreteCallback(condition,affect!)

sol = solve(prob,Tsit5(),callback=cb, tstops=[4.0])
Plots.plot(sol)

```

I can not understand why the value is not written to the “check” variable? If instead of “check = integrator.u[1]” I write “print(integrator.u[1])”, then it works, and the value I need is displayed on the screen. And how to remember it in some kind of variable, so that later it can be used somewhere else?

---

<div class="post-metadata">

### Author: ![goerch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerch/32/29122_2.png) [@goerch](https://discourse.julialang.org/u/goerch)
#### Post date: [March 16, 2022, 10:17pm UTC](https://discourse.julialang.org/t/how-to-get-system-state-during-event-handling/77994/2 "2022-03-16T22:17:17Z")

</div>

Shot in the dark: probably a missing

```julia
    global check = integrator.u[1]

```

?

> [@egor](#):
>
> And how to remember it in some kind of variable, so that later it can be used somewhere else?

Good question, I’d expect some kind of parameter for user data, too.
