Out of scope inside function but don't know how to fix it. tried global no luck

Use a Ref:

julia> const CC = Ref(5)                                                                          
Base.RefValue{Int64}(5)                                                                           
                                                                                                  
julia> CC[]                                                                                       
5                                                                                                 
                                                                                                  
julia> CC[] = 6                                                                                   
6                                                                                                 
                                                                                                  
julia> CC[]                                                                                       
6              
 
julia> function g()                                                                               
       global CC                                                                                  
       CC[] = 0                                                                                   
       end                                                                                        
g (generic function with 1 method)                                                                
                                                                                                  
julia> g()                                                                                        
0                                                                                                 
                                                                                                  
julia> CC[]                                                                                       
0                                                                                                 
                                                                                                  
julia>                                                                                   
1 Like