Does anyone know if there is a way to access variables outside of a module? Basically, i have a storyboard scene with local variables and i’d like to be able to access those variables within a character module i made. I don’t want to have to pass the local variables to each character object. Any ideas? Here is an example of what i am trying to do.
Excerpt from sample_scene.lua
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
-- Forward declarations and other locals
local score = 0
local Character = require( "character" )
Excerpt from character.lua
[code]
module(…, package.seeall)
function new( params )
print( score )
end
[/code] [import]uid: 26491 topic_id: 30602 reply_id: 330602[/import]
2 Options:
- you can declare global variables like this
\_G.myNewGlobalVariable = "globally accessible string"
- use the storyboard module to pass vars
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
storyboard.score = 0
-finefin [import]uid: 70635 topic_id: 30602 reply_id: 122603[/import]
Is there any other way to do this? I’d rather not use a global variable, and i don’t think the storyboard variables work in a module that doesn’t require storyboard. [import]uid: 26491 topic_id: 30602 reply_id: 122676[/import]
2 Options:
- you can declare global variables like this
\_G.myNewGlobalVariable = "globally accessible string"
- use the storyboard module to pass vars
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
storyboard.score = 0
-finefin [import]uid: 70635 topic_id: 30602 reply_id: 122603[/import]
well, you could also write your own module that stores your data. again, you have to require it in to every module that needs to access that data. [import]uid: 70635 topic_id: 30602 reply_id: 123172[/import]
Is there any other way to do this? I’d rather not use a global variable, and i don’t think the storyboard variables work in a module that doesn’t require storyboard. [import]uid: 26491 topic_id: 30602 reply_id: 122676[/import]
well, you could also write your own module that stores your data. again, you have to require it in to every module that needs to access that data. [import]uid: 70635 topic_id: 30602 reply_id: 123172[/import]