Created
October 25, 2018 18:38
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
z: 45 | |
a: 9 | |
This is the value of z / x = 20 | |
a: 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
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
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"