# Abnormal behaviour when using callback two times in the same script

**URL:** <https://discourse.julialang.org/t/abnormal-behaviour-when-using-callback-two-times-in-the-same-script/126062>\
**Category:** Modelling & Simulations\
**Tags:** question\
**Created:** [February 19, 2025, 10:23am UTC](https://discourse.julialang.org/t/abnormal-behaviour-when-using-callback-two-times-in-the-same-script/126062 "2025-02-19T10:23:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sushrut\_Deshpande](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sushrut_deshpande/32/52754_2.png) [@Sushrut\_Deshpande](https://discourse.julialang.org/u/Sushrut_Deshpande)\
**Post date:** [February 19, 2025, 10:23am UTC](https://discourse.julialang.org/t/abnormal-behaviour-when-using-callback-two-times-in-the-same-script/126062/1 "2025-02-19T10:23:05Z")

</div>

Hello,  
I have a MWE here for when I solve a ODE with callback two times in the same script , it solves the first one case expected and does not for the second one.

```julia
using DifferentialEquations, Plots, OrdinaryDiffEq

function du!(du,u,p,t)
    du .= -p[1]*ones(length(u))
end

function condition1(u, t, integrator) # Event when condition(u,t,integrator) == 0
    u[1] 
end
function floor_aff1(int)
    int.p[1] = 0 
end
function condition2(u, t, integrator) # Event when condition(u,t,integrator) == 0
    u[1] 
end
function floor_aff2(int)
    int.p[1] = 0 
end

u0 = [1.0]
tspan = (0.0,2.0)
p = [1.0]
prob = ODEProblem(du!,u0,tspan,p)
cb = ContinuousCallback(condition1, floor_aff1)
sol = solve(prob, Tsit5(), callback = cb)
plot(sol,label = "Case 1")

prob2 = ODEProblem(du!,u0,tspan,p)
cb2 = ContinuousCallback(condition2, floor_aff2)
sol2 = solve(prob2, Tsit5(), callback = cb2)
plot!(sol2,label = "Case 2")

```

Plot:

 ![bug_callback](https://global.discourse-cdn.com/julialang/original/3X/a/a/aad9dda9e8d0a4d044e677b502614ca99ef1eaec.png)

both should have the exact same solution. I have also renamed the callback functions so that there is no overlap.

---

<div class="post-metadata">

**Author:** ![Sushrut\_Deshpande](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sushrut_deshpande/32/52754_2.png) [@Sushrut\_Deshpande](https://discourse.julialang.org/u/Sushrut_Deshpande)\
**Post date:** [February 19, 2025, 12:05pm UTC](https://discourse.julialang.org/t/abnormal-behaviour-when-using-callback-two-times-in-the-same-script/126062/2 "2025-02-19T12:05:02Z")

</div>

It rewrites `p` after the first call back need to duplicate it as well.
