Hello all.
I have been working on trying to get this to work all day. I want to move a set of global functions to a modular file. My first attempt is to try creating a function to pass a scene name to and have that function change scenes. Is this possible to do? Here is the code I came up with but no matter what I do it just returns a nil value. I am new to Lua. I was reading all the material I could find on modulation and passing to functions. Any help would be appreciated.
Here is a compressed version of all perftinent code in my menu.lua file
local composer = require( "composer" )
local gF = require("globalFunctions")
local scene = composer.newScene()
-- -----------------------------------------------------------------------------------
-- Code outside of the scene event functions below will only be executed ONCE unless
-- the scene is removed entirely (not recycled) via "composer.removeScene()"
-- -----------------------------------------------------------------------------------
-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------
-- create()
function scene:create( event )
--Menu Buttons
----Play Button
local playButton = display.newText( sceneGroup, "PLAY", display.contentCenterX, 240, native.systemFont, 60 )
playButton:setFillColor( 0.82, 0.86, 1 )
playButton:addEventListener( "tap", gF.switchScene(game) )
----Credits Button
local creditsButton = display.newText( sceneGroup, "CREDITS", display.contentCenterX + 165, 270, native.systemFont, 30)
creditsButton:setFillColor( 0.82, 0.86, 1 )
creditsButton:addEventListener( "tap", gF.switchScene(credits) )
end
-- show()
--etc...
-- hide()
--etc...
-- destroy()
--etc...
-- -----------------------------------------------------------------------------------
-- Scene event function listeners
-- -----------------------------------------------------------------------------------
--etc...
-- -----------------------------------------------------------------------------------
return scene
Here is the globalFunctions.lua file it requiresā¦
------------------------------------------------------
-- Pseudo-global space ///FUNCTIONS
------------------------------------------------------
local gV = require( "globalVariables" )
local M = {}
--Navigation
M.switchScene = function(toScene)
composer.gotoScene( ""..toScene.."", { time=800, effect="crossFade" } )
end
return M