external lua file

Hello everyone,

I’m super new to Corona and the Lua languange. I’m coming from a flash and actionscript 1 and 2 background so I’m trying to wrap my head around this stuff. I’m using require to load an external lua file (screen1.lua) containing a interface I created into my main.lua . Once I do that is there any way to reference screen1.lua so that I can scale, move or animate it? I’ve tried giving it a variable name but I can’t seem to get it to work. Can I only reference things like functions and objects and not the whole external lua file? Here’s what I’ve done as a test so far…

local externalPage = require(“screen1”)
externalPage.x = 100

Any help will be greatly appreciated. Thanks!

L [import]uid: 52296 topic_id: 8807 reply_id: 308807[/import]

@Larry, you might want to check out some samples on the Code Exchange, that will give you a lot of examples of what you are after.

cheers,

?:slight_smile: [import]uid: 3826 topic_id: 8807 reply_id: 32087[/import]

Hi larry, I’m a noob too, but I think using a displayGroup might help you.
Heres some of the code for something I’m programming atm.
I may have mangled it pulling the relevant bits out, but here goes

[lua]local spellGroup = display.newGroup()
spellBookFrame = display.newImage(“general_frame.png”,0,0);
spellBookFrame.x = display.contentWidth / 2
spellBookFrame.y = display.contentHeight / 2

local name = display.newText(spell.name,0,0,“Papyrus”,{0,0,0})
local desc = display.newText(spell.desc,0,0,“Papyrus”,{0,0,0})
local hitBox = display.newRect(0,0,200,75)
hitBox:setFillColor(0,0,200,129)
spellGroup:insert(hitBox)
spellGroup:insert(name)
spellGroup:insert(desc)
hitBox.yOrigin = 0
name.yOrigin = -20
desc.yOrigin = 30[/lua]

so basically
your screen1.lua will look something like this

[lua]module(…, package.seeall) --not sure if this is needed, doesnt seem to hurt

screen1 = display.newGroup()
item1 = display.newRect(…)
item2 = display.newImage(…)
screen1:insert(item1)
screen1:insert(item2)[/lua]

and your main.lua (or whatever is using it) will look something like this

[lua]require(screen1)
screen1.x = 100
screen1.y = 200
–etc…[/lua]

hope that made some kind of sense, anyway, use the director class, its pretty well documented on here, and makes it all so much easier :slight_smile:
if it didnt make sense, say so and I’ll try again! :smiley: [import]uid: 34945 topic_id: 8807 reply_id: 32245[/import]

http://developer.anscamobile.com/code/object-oriented-sample-game-framework [import]uid: 12108 topic_id: 8807 reply_id: 32266[/import]

Thanks everybody. You’ve pointed me in the right direction here. Much appreciated! [import]uid: 47290 topic_id: 8807 reply_id: 34252[/import]