# Makie on() do block does not see a variable

**URL:** <https://discourse.julialang.org/t/makie-on-do-block-does-not-see-a-variable/104918>\
**Category:** Visualization\
**Tags:** observables\
**Created:** [October 13, 2023, 5:49am UTC](https://discourse.julialang.org/t/makie-on-do-block-does-not-see-a-variable/104918 "2023-10-13T05:49:03Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oscarvdvelde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscarvdvelde/32/202157_2.png) [@oscarvdvelde](https://discourse.julialang.org/u/oscarvdvelde)\
**Post date:** [October 13, 2023, 5:49am UTC](https://discourse.julialang.org/t/makie-on-do-block-does-not-see-a-variable/104918/1 "2023-10-13T05:49:03Z")

</div>

I am in this situation:

```julia
on(topbutton[4].clicks) do click 
    lma,lmaheader,lmafile,tim,xy,tz = load_lma_data(lmafolder,lmafile,1)
    selection[] = lma.qua .&& (0 .< tim .<= 600)
end  

```

Result: `Error in callback: UndefVarError: `lmafile` not defined Stacktrace: [1] (::var"#196#197")(click::Int64) @ Main .....etc.`

However, the following just returns the strings without problem:

```julia
on(topbutton[4].clicks) do click
    println(lmafolder)
    println(lmafile)
end   

```

Also, in the REPL I can call without problem:  
`lma,lmaheader,lmafile,tim,xy,tz = load_lma_data(lmafolder,lmafile,1)`

What am I missing?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [October 13, 2023, 7:49am UTC](https://discourse.julialang.org/t/makie-on-do-block-does-not-see-a-variable/104918/2 "2023-10-13T07:49:42Z")

</div>

I assume you have `lmafile` as a variable in an outer scope. But in this line

```julia
lma,lmaheader,lmafile,tim,xy,tz = load_lma_data(lmafolder,lmafile,1)

```

you assign to it on the left-hand side, which probably causes it to be treated as a local variable in the whole scope, so it doesn’t exist yet when you want to use it as a function argument. At least that’s my guess.

---

<div class="post-metadata">

**Author:** ![oscarvdvelde](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscarvdvelde/32/202157_2.png) [@oscarvdvelde](https://discourse.julialang.org/u/oscarvdvelde)\
**Post date:** [October 13, 2023, 7:58pm UTC](https://discourse.julialang.org/t/makie-on-do-block-does-not-see-a-variable/104918/3 "2023-10-13T19:58:44Z")

</div>

You are right, it is the variables on the left-hand side. I then tried this:

```julia
    lma2,lmaheader2,lmafolder2,lmafile2,tim2,xy2,tz2 = load_lma_data(lmafolder,lmafile,1)
    # lma = lma2; lmaheader = lmaheader2;
    # lmafolder = lmafolder2; lmafile = lmafile2;
    # tim = tim2; xy = xy2; tz = tz2; 
    selection[] = lma.qua .&& (0 .< tim .<= 600)
end

```

Like this, it loads the new data but does not display it, as it remains local. I cannot seem to find a simple way to update the global variables with the new data. Enabling the commented lines trigger the same error in the line before, where the function is called. I also tried a form of `lma_load_data!` without success. What would be the right way to do it?

Update! It works just by using:

```julia
global lma,lmaheader,lmafolder,lmafile,tim,xy,tz = load_lma_data(lmafolder,lmafile,-1)

```
