So, I am testing somethings out, and have a “test” proc like so:
proc test {arg} {
global state
puts "Your arg is: $arg"
set state 1
}
test somearg
vwait state
From reading about uplevel and upvar, is there a way that I can get away with not having to use global, and use either one of those options to set the state to “1” and then exit the program?
Yes, except that
vwaitalways uses global variables for waiting on (strictly, it resolves variable names in the global scope; you can use other namespaces if you provide qualified names). What you can’t do is wait on a local variable (because events can’t see local variables outside their own call stack). Maybe this will change in the future, but certainly not now.In relation to the question about
global, these statements are all the same in effect inside a procedure:You also have a bug in your code: you set the state before waiting for it to change. That won’t work anyway because you’ve got to wait first, and set the state from within some kind of event.