Trying to "centralise" a table

Hi Everyone, my first Corna project is going well thanks to the generous guys on the forum.

My project consists of several screens (lua files) and I have tables that need to be used in each of them. Instead of declaring these tables locally in each of the lua files, I would like to centralise the table declarations to another lua file as global variables and then “require” them into the screen files. This way everytime I change a table, I won’t have to update it in every lua file.

I have seen examples of using functions within external lua files but how would I retrieve table data.

For example, I create a lua file called test.lua and my table is

local table1 = {

{ name = “111”, type = “1”},
{ name = “222”, type = “2”},
{ name = “333”, type = “3”}
}

I know I need to

test1 = require (“test”)

How would I retrieve the table data? Would it be test1.table1.name or test1.name? Or am I miles off?

Thanks

Adrian

[import]uid: 83824 topic_id: 15754 reply_id: 315754[/import]

Remove the “local” from your table1 in test.lua

Change [lua]test1 = require “test”[/lua] to;
[lua]local test1 = require “test”[/lua]

Then you can see values like so;
[lua]print (test1.table1[1].name)[/lua]
OR
[lua]print (test.table1[1].name)[/lua]

Either should print 111.

Peach :slight_smile: [import]uid: 52491 topic_id: 15754 reply_id: 58159[/import]

Thanks Peach - you’re an angel! Makes everything far more compact and managaable.

Adrian [import]uid: 83824 topic_id: 15754 reply_id: 58324[/import]

Hi,
Could You tell me how to manage (move from - to another ,copy from - to another, delete) some objects contained in two tables that have objects with proprieties (speed, image,…)?

general ex:

[lua]local table1={
object1={

{},{},{}
},

object2={

{},{},{}
}

object3={

{},{},{}
},

}

local table2={
object5={

{},{},{}
},

object4={

{},{},{}
},

object6={

{},{},{}
}

}[/lua]

[import]uid: 65047 topic_id: 15754 reply_id: 58329[/import]

Thanks Adrian :slight_smile:

@sewfew2000 - Take a look at this tutorial by Jon Beebe; http://blog.anscamobile.com/2011/06/understanding-lua-tables-in-corona-sdk/ [import]uid: 52491 topic_id: 15754 reply_id: 58341[/import]