# PresetTimeCallback with array in affect function

**URL:** <https://discourse.julialang.org/t/presettimecallback-with-array-in-affect-function/131806>\
**Category:** General Usage\
**Tags:** diffeqcallbacks\
**Created:** [August 24, 2025, 11:45am UTC](https://discourse.julialang.org/t/presettimecallback-with-array-in-affect-function/131806 "2025-08-24T11:45:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco\_Masi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marco_masi/32/212305_2.png) [@Marco\_Masi](https://discourse.julialang.org/u/Marco_Masi)\
**Post date:** [August 24, 2025, 11:45am UTC](https://discourse.julialang.org/t/presettimecallback-with-array-in-affect-function/131806/1 "2025-08-24T11:45:44Z")

</div>

I’m trying to understand how to use the `PresetTimeCallback(tstops,affect!)` where tstops is an array of time steps and the affect function should also affect the integration each time with different values.  
For example, for one time and one affect I used:

```julia-auto
DE.PresetTimeCallback(t1, integrator -> integrator.p[1] += v1)

```

This works.  
For a list of timesteps

```julia-auto
DE.PresetTimeCallback([t1, t2, t3], integrator -> integrator.p[1] += v1);

```

works as well. It just applies the same v1.  
However, I would like it to apply at each different time t1, t2, t3, … the values v1, v2, v3… I tried something sort of…

```julia-auto
DE.PresetTimeCallback([t1, t2, t3], integrator -> integrator.p[1] += [v1, v2, v3]);

```

but that doesn’t work.  
Any suggestion how to do that?

---

<div class="post-metadata">

**Author:** ![isaacsas](https://avatars.discourse-cdn.com/v4/letter/i/f6c823/32.png) [@isaacsas](https://discourse.julialang.org/u/isaacsas)\
**Post date:** [August 24, 2025, 11:57am UTC](https://discourse.julialang.org/t/presettimecallback-with-array-in-affect-function/131806/2 "2025-08-24T11:57:08Z")

</div>

Have your affect function increment a counter each time it is called and use that to index into the vector of `v` values. This would probably work well as a [function-like object](https://docs.julialang.org/en/v1/manual/methods/#Function-like-objects) (to avoid global variables).
