How to access an image declared in a module?

Hi guys, in my game.lua file I have:
 

local sprites = require("sprites.lua")

sprites.lua contains

local iceberg = display.newImage("iceberg.png") iceberg.x = \_W/2 iceberg.y = \_H/2 iceberg.alpha = 1

Now, I’d like to set “iceberg.alpha” to 0 from “game.lua”, but If I try, Corona returns “attempt to index global iceberg (a nil value)”

Of course, sprites.lua contains

module(..., package.seeall)

What am I doing wrong?

I’ve even tried to use sprites.iceberg.alpha = 0, but obviously it doesn’t work.

Thank you.

While Corona probably could improve its documentation for the canonical way to create modules, this isn’t especially difficult. Create a method in your sprites module that might look something like this:

function sprites:setAlpha( value )   iceberg.alpha = value end

There are other ways to do this but that might be the simplest.

Also note that you might want to avoid the module() function, which is effectively deprecated:

http://coronalabs.com/blog/2011/09/05/a-better-approach-to-external-modules/

Thank you, and sorry if I’m replying just now.

I tried what you have suggested and it works great!

Sorry but I hadn’t noticed yet that the module() function is deprecated.

Bye.

While Corona probably could improve its documentation for the canonical way to create modules, this isn’t especially difficult. Create a method in your sprites module that might look something like this:

function sprites:setAlpha( value )   iceberg.alpha = value end

There are other ways to do this but that might be the simplest.

Also note that you might want to avoid the module() function, which is effectively deprecated:

http://coronalabs.com/blog/2011/09/05/a-better-approach-to-external-modules/

Thank you, and sorry if I’m replying just now.

I tried what you have suggested and it works great!

Sorry but I hadn’t noticed yet that the module() function is deprecated.

Bye.