The golden rule regarding variables is that global variables are forbidden. The Xilinx Tcl Store linter checks for global variables inside the scripts and generates an error message if any global variable is defined.
If some variables need to be shared within procs of an app, then they should be declared inside the namespace. This is done by creating the variables with the keyword variable
inside the namespace. Such variables can be used like global variables, but only within the namespace.
The code below creates the variable verbose
that can be shared within all the procs that belong to the same namespace. The variable is initialized to 0:
namespace eval ::tclapp::mycompany::template {
variable verbose 0
}
To access the variable inside a proc, the variable should be declared with the keyword variable
inside the proc.
For example:
proc ::tclapp::mycompany::template::::my_command1::my_command1 { args } {
variable verbose
# The variable verbose can be accessed here
set verbose 1
}
proc ::tclapp::mycompany::template::my_command1::helper1 { args } {
variable verbose
# The variable verbose can be accessed here
if {$verbose} {
..
}
}
verbose
can also be accessed from any namespace (including the global namespace) by using the full namespace qualifier. For example:set ::tclapp::mycompany::template::verbose 1