Skip to content

Instantly share code, notes, and snippets.

@IamFlowZ
Created October 25, 2018 18:38
Show Gist options
  • Save IamFlowZ/a732488c0cbf81ab53bbd08ecb8ce0e6 to your computer and use it in GitHub Desktop.
Save IamFlowZ/a732488c0cbf81ab53bbd08ecb8ce0e6 to your computer and use it in GitHub Desktop.
When I instantiate "mine" outside of the if statement, it won't change the value from within the condition. But it will execute the "set a" portion of the statement inside the condition.
z: 45
a: 9
This is the value of z / x = 20
a: 20
set mine ""
set z 100
if {$z > 200} {
set mine [puts "This is the value of z * x = [set a [expr {$z * $x}]]"]
} else {
set mine [puts "This is the value of z / x = [set a [expr {$z / $x}]]"]
}
puts $a
puts "This is me storing the command in a variable, \$mine = $mine"
@IamFlowZ
Copy link
Author

IamFlowZ commented Oct 26, 2018

set mine ""
set x 5
set z 100
;#I want to make it so I store the literal value of the line before it's executed, followed by executing the line.
;#That way if you call elsewhere, the command is optionally maleable before it's executed.
if {$z > 200} {
upvar 0 mine answer
set answer {[set a [expr {$z * $x}]]}

} else {
upvar 0 mine answer
set answer {[set a [expr {$z / $x}]]}
}

expr $mine == 1
puts "mine: $mine"
puts "a has been changed: $a"

@IamFlowZ
Copy link
Author

Didn't know about upvar, also I know setting to global is bad, if this was in a function I would set it to one. So I would be stepping out one level.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment