lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


In your example just declare strMessage etc as local before the first if statement; no need to assign a value they will default to nil

--Tim

> On Aug 23, 2014, at 8:05 PM, Paul Merrell <marbux@gmail.com> wrote:
> 
> Hi, all,
> 
> After a couple of years now, I think I'm approaching an understanding
> of Lua's variable scoping. But where I'm still at sea is in evading
> the use of globals in an if block or loop inside a function. I feel
> like I'm missing something basic. An example at
> <https://gist.github.com/Marbux/961d5aa3244993e42cae>, which executes
> but is a work in progress.
> 
> A function begins at line 43 and a series of if blocks at line 48.
> The variables within each if block are globals. How might I refactor
> my function so that the same variables are locals, if possible.
> 
> I've been working around this kind of problem by declaring the globals
> as nils in the global environment. See function test at line 79. But
> particularly with functions shared by multiple scripts, I'd like to
> find a way around that.
> '
> Hopefully, this is just my ignorance showing. I'll appreciate any
> enlightenment here.
> 
> Best regards,
> 
> Paul
> 
> Best regards,
> 
> Paul
> 
> 
> 
> 
> -- 
> [Notice not included in the above original message:  The U.S. National
> Security Agency neither confirms nor denies that it intercepted this
> message.]
>