How to pass variable from another lua file?

How to pass variable from another lua file? Im trying to pass the text variable title to another b.lua as a text.

--a.lua file local options = { title = "Easy - Addition", backScene = "scenes.operationMenu", } --b.lua file local score\_label\_2 = display.newText({parent=uiGroup, text=title, font=native.systemFontBold, fontSize=128, align="center"})

Hi KilikSky , 

Follow the following steps.

[lua]

–sender.lua

local data={}

data.options={

                           title = “ASSIF”,

                           backScene= “lala.lua”

                       }

data.name=“HI THIS IS LALA”

function data.myFunction( )

          print(" I AM A FUNCTION WHOSE REFERENCE IS STORED IN data table")

     

end

return data

[/lua]

now require the sender.lua in the file where you want to use it or require it globally in main file, so that you can use it directly.

[lua]

–Any Receiver Scene where it data to be used for ex : receiiver.lua

obj = require(“sender”)

print(obj.options.title)

print(obj.options.backScene)

print(obj.name)

obj.myFunction( )

[/lua]

Note : If you only want to pass from One Scene to another Scene  you can also use composer.setVariable() & composer.getVariable() methods.

-Assif

Hi KilikSky , 

Follow the following steps.

[lua]

–sender.lua

local data={}

data.options={

                           title = “ASSIF”,

                           backScene= “lala.lua”

                       }

data.name=“HI THIS IS LALA”

function data.myFunction( )

          print(" I AM A FUNCTION WHOSE REFERENCE IS STORED IN data table")

     

end

return data

[/lua]

now require the sender.lua in the file where you want to use it or require it globally in main file, so that you can use it directly.

[lua]

–Any Receiver Scene where it data to be used for ex : receiiver.lua

obj = require(“sender”)

print(obj.options.title)

print(obj.options.backScene)

print(obj.name)

obj.myFunction( )

[/lua]

Note : If you only want to pass from One Scene to another Scene  you can also use composer.setVariable() & composer.getVariable() methods.

-Assif