How can i get or pass the value from one lua file to another lua file??
If you are meaning source files (e.g. code) then you can’t except using globals and really you shouldn’t. A lua module is just a repository of code - just really a way of avoiding having one enormous file.
In terms of the code in the files this happens the same way as in any other piece of code, you can pass parameters to functions and so on. Modules often return an object reference which can contain methods/functions but this isn’t actually required.
shuffle_scene:
local composer = require (“composer”);
local sceneNames = {“scene1”,“scene2”,“scene3”,“scene4”, “scene5”, “scene6”, “scene7”};
for count=1, 0 do
sceneNames[count] = count
end
local function shuffle(t)
local iterations = #t
local j
for count = iterations,2, -1 do
j = math.random(count)
t[count], t[j] = t[j], t[count]
end
end
shuffle(sceneNames)
composer.gotoScene(sceneNames[1]);
the problem is when I go to the shuffled scene (e.g scene3) I need to get the index value sceneNames[2] which is (e.g scene1) from the shuffle_scene and so on and forth
Setup a new .lua file called something like globals.lua:
[lua]
local glo = {}
glo.sceneNames = {“scene1”,“scene2”,“scene3”,“scene4”, “scene5”, “scene6”, “scene7”};
return glo
[/lua]
Then at the top of each scene:
[lua]
local glo = require (“globals”)
[/lua]
Then you can either replace your sceneNames references with glo.sceneNames, or do:
[lua]
local sceneNames = glo.sceneNames
[/lua]
then I can get the value ^^
module 'globals ’ not found
If you are meaning source files (e.g. code) then you can’t except using globals and really you shouldn’t. A lua module is just a repository of code - just really a way of avoiding having one enormous file.
In terms of the code in the files this happens the same way as in any other piece of code, you can pass parameters to functions and so on. Modules often return an object reference which can contain methods/functions but this isn’t actually required.
shuffle_scene:
local composer = require (“composer”);
local sceneNames = {“scene1”,“scene2”,“scene3”,“scene4”, “scene5”, “scene6”, “scene7”};
for count=1, 0 do
sceneNames[count] = count
end
local function shuffle(t)
local iterations = #t
local j
for count = iterations,2, -1 do
j = math.random(count)
t[count], t[j] = t[j], t[count]
end
end
shuffle(sceneNames)
composer.gotoScene(sceneNames[1]);
the problem is when I go to the shuffled scene (e.g scene3) I need to get the index value sceneNames[2] which is (e.g scene1) from the shuffle_scene and so on and forth
Setup a new .lua file called something like globals.lua:
[lua]
local glo = {}
glo.sceneNames = {“scene1”,“scene2”,“scene3”,“scene4”, “scene5”, “scene6”, “scene7”};
return glo
[/lua]
Then at the top of each scene:
[lua]
local glo = require (“globals”)
[/lua]
Then you can either replace your sceneNames references with glo.sceneNames, or do:
[lua]
local sceneNames = glo.sceneNames
[/lua]
then I can get the value ^^
module 'globals ’ not found