# Variable global scope

**URL:** <https://discourse.julialang.org/t/variable-global-scope/58518>\
**Category:** New to Julia\
**Created:** [April 3, 2021, 7:17pm UTC](https://discourse.julialang.org/t/variable-global-scope/58518 "2021-04-03T19:17:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rverdier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rverdier/32/9104_2.png) [@rverdier](https://discourse.julialang.org/u/rverdier)\
**Post date:** [April 3, 2021, 7:17pm UTC](https://discourse.julialang.org/t/variable-global-scope/58518/1 "2021-04-03T19:17:00Z")

</div>

In creating a Julia script for interactive plotting of compound interest and mortgages, I’ve run into a problem. Here’s a skeleton of the essential parts:

```julia
using Gtk
w, h = 200, 250
canvas = @GtkCanvas()
win = GtkWindow(canvas, "Interest", w, h)
amount = 1000
initialamount = 1000

function plotcurve()
  return 999
end 

@guarded draw(canvas) do widget
    gc = getgc(canvas)
    global amount
    amount = plotcurve()
    println("draw set amount=$amount") # amount changed correctly
end # do

function process()
println("process called with amount = $amount")
  draw(canvas)
  showall(win)
  println("process: initial amount=$initialamount, finalamount=$amount") # amount unchanged
end # process function

process()
  println("initial amount=$initialamount, finalamount=$amount") # amount unchanged

```

Here’s the result of running it as an included script:

```julia
julia> include("desktop/globaltest.jl.txt")
process called with amount = 1000
process: initial amount=1000, finalamount=1000
initial amount=1000, finalamount=1000

julia> draw set amount=999

```

How can the correct value of amount, as set in the draw function, be passed to the global variable, as needed in the full implementation? As this is for a course I’m creating, the simplest solution is desirable. Thanks for any help.

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [April 3, 2021, 9:14pm UTC](https://discourse.julialang.org/t/variable-global-scope/58518/2 "2021-04-03T21:14:36Z")

</div>

Sorry, I was not able to reproduce the problem, I am on

```julia
julia> versioninfo()
Julia Version 1.5.3
Commit 788b2c77c1 (2020-11-09 13:37 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-9.0.1 (ORCJIT, skylake)

```

and for me `using Gtk` gives

```julia
[Info: Precompiling Gtk [4c0ca9eb-093a-5379-98c5-f87ac0bbbf44]
ERROR: LoadError: LoadError: InitError: could not load library "/home/henrique/.julia/artifacts/079e2f87254bb2465a44de255cd5dde50d4d0b62/lib/libpangocairo-1.0.so"
/usr/lib/libpangoft2-1.0.so.0: undefined symbol: pango_coverage_get_type
...
ERROR: LoadError: Failed to precompile GTK3_jll [77ec8976-b24b-556a-a1bf-49a033a670a6] to /home/henrique/.julia/compiled/v1.5/GTK3_jll/D35Um_6iwJ1.ji.
...
ERROR: Failed to precompile Gtk [4c0ca9eb-093a-5379-98c5-f87ac0bbbf44] to /home/henrique/.julia/compiled/v1.5/Gtk/Vjnq0_6iwJ1.ji.

```

---

<div class="post-metadata">

**Author:** ![rverdier](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rverdier/32/9104_2.png) [@rverdier](https://discourse.julialang.org/u/rverdier)\
**Post date:** [April 9, 2021, 1:05am UTC](https://discourse.julialang.org/t/variable-global-scope/58518/3 "2021-04-09T01:05:19Z")

</div>

Well, thanks for trying. My Platform Info is just like yours except on MacBookPro, so another entry for the Journal Of Irreproducible Results. It’s now clear that JuliaGtk does not support variables with global scope, so I’ve rewritten the original example so the calculations are done outside the draw function.
