A simple advice for a noob

Hello guys I 'm new in coding

In fact I have a simple question for you.

I have 3 files.lua linked by a STORYBOARD

In file1.lua I have a variable memorized (  local A= 1 )

In file2.lua I have a variable memorized (  local B= 2 )

I want to print the result of A+B in file3.lua… Is possible to do this??? and If yes How can I do ?

thanks for the attention

Kind Regards

The “simple but wrong” way would be to create global variables. A bit more work, but a better way of doing it (and perhaps answering your implied question of how to share data among modules in general) is to create a shared module. Rob (staff) might chime in with: http://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/ (recommended reading) If you follow that guide, you might end up with a strategy something like this:

– SharedData.lua
local M={}
M.a = 0
M.b = 0
return M

– Scene1.lua
local sd = require(“SharedData”)
sd.a = 123

– Scene2.lua
local sd = require(“SharedData”)
sd.b = 234

– Scene3.lua
local sd = require(“SharedData”)
print(sd.a + sd.b )
– will print 357 (assuming scene 1 and 2 have already run, of course)

You are my heroe thanks a lot bro

The “simple but wrong” way would be to create global variables. A bit more work, but a better way of doing it (and perhaps answering your implied question of how to share data among modules in general) is to create a shared module. Rob (staff) might chime in with: http://coronalabs.com/blog/2013/05/28/tutorial-goodbye-globals/ (recommended reading) If you follow that guide, you might end up with a strategy something like this:

– SharedData.lua
local M={}
M.a = 0
M.b = 0
return M

– Scene1.lua
local sd = require(“SharedData”)
sd.a = 123

– Scene2.lua
local sd = require(“SharedData”)
sd.b = 234

– Scene3.lua
local sd = require(“SharedData”)
print(sd.a + sd.b )
– will print 357 (assuming scene 1 and 2 have already run, of course)

You are my heroe thanks a lot bro