kuwalda Posted July 8, 2014 Share Posted July 8, 2014 So I have had this question for a while and am a little ashamed to ask it, but still - if I store something on variable, for example: X = 2 + 2 Then when after using this variable X ,do it make out this variable by doing what is after = mark OR X is already assumed to be 4 and whenever using it, it will return this 4, because system figured this out 1 time and won`t check again. Don`t get me wrong - we all know that 2+2=4 ,but my question is about that, if this value is calculated only 1 time or just replaces this action with letter X? Result is = X // Result is = 4 Result is = X // Result is 2+2 (system calculates, won`t show this to user) // Result is = 4 I really hope you guys understanded my point. Link to comment
Arnold-1 Posted July 9, 2014 Share Posted July 9, 2014 X = 2 + 2 means X = 4 It's actually the only way to calculate numbers, we don't have functions for that. Link to comment
xXMADEXx Posted July 9, 2014 Share Posted July 9, 2014 X = 2 + 2 means X = 4It's actually the only way to calculate numbers, we don't have functions for that. That's not really what he was asking.. The variable is assigned, when the variable is assigned. I had this question to for a while but decided to put it to a test. Link to comment
Den. Posted July 11, 2014 Share Posted July 11, 2014 I think once the calculation 2+2 is done, the result (4) is stored in memory under 'x'. If you access x afterwards, its value will be fetched from memory regardless of what calculation produced its result. Example: function add(left, right) outputChatBox("Adding") return left[1] + right[1] end addCommandHandler('test1', function() local t1 = {1} local t2 = {2} setmetatable(t1, {__add = add}) local x = t1 + t2 outputChatBox("Result1: "..tostring(x)) outputChatBox("Result2: "..tostring(x)) end) Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now