Thread Tools Display Modes
Prev Previous Post   Next Post Next
06-24-18, 07:36 PM   #1
seyan777
An Aku'mai Servant
Join Date: Feb 2017
Posts: 35
Basic question regarding variable scope

Hi all!

Just a super quick question about variable scope.

Lua Code:
  1. local testVar = 1;
  2.  
  3. function testFunc()
  4.     local testVar = testVar;
  5.  
  6.     print(testVar);
  7.  
  8.     testVar = 2;
  9. end
  10.  
  11. testFunc();
  12.  
  13. print(testVar);

For the code snippet above, it would print 1 for both testVar.

The question is, can you change the value of outer variable even if you declare a new local variable with an outer one's name within a function? or should I prevent such circumstances if I'd like to do so?

Last edited by seyan777 : 06-24-18 at 07:38 PM.
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Basic question regarding variable scope

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off