local var question

[lua]local background
local function display()
background = display.newImageRect(“PIC.png”, 79, 80)
end

or

local function display()
local background = display.newImageRect(“PIC.png”, 79, 80)
end[/lua]

which is better? [import]uid: 40786 topic_id: 12228 reply_id: 312228[/import]

@phongyewtong,
both are sueful depending on what you want to do.

in sample #1,
you can access background from other functions and later on down the code

in sample #2,
you cannot access the variable background, so it’s there on screen but you have no access to it.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 12228 reply_id: 44546[/import]