So, I was working with a bit of simple code. First I created a few mods; globalVariables, globalFunctions. Then I designed the game to start on a home.lua pointed at from a menu.lua. From there the user will be able to navigate to different scenes; zone1, zone2, etc. I also made a few veritable Lua files called game1.lua, game2.lua, game3.lua, ect. as places for the user to save there game in a type of “game slot”. The idea here is to use the require function to auto load information for each saved game, such as armor, weapons, and as in the case below, player scene location. (as the player will want to always start at the scene they last left.)
So, here is where my question comes into play. In the following code, I have attempted to require a dynamic game#.lua within my globalFunctions.lua file by implementing the following code. When I run it; however, I get an error message which says, “bad argument #1 to ‘find’ (string expected, got nil)” My thinking is the variable in the require function should point to a string value as is. Unless a variable is not an accepted argument for a require function. Which, might be what this error message is trying to say to me… If so, is there another way this can be done?
NOTE: The variable currentGameID, which is in the globalVariables Module, is a number value that will change based on what character the player chooses to play during their session. Currently, this code works for all scene changes except the ‘default’ one.
UPDATE: I changed the code below so that the defaultScene function code reads: gV.currentScene = “home”. Now, it is identical to the code in the following functions which work. Oddly I am still getting the same error message! I am now at a complete loss for understanding why this is bugged.
local composer = require("composer")
local gV = require( "globalVariables" )
local ui = require( "userInterface")
local currentGame = "game"..tostring(gV.currentGameID)
local game = require( currentGame )
local M = {}
--Scene Navigation
M.defaultScene = function()
gV.currentScene = game.playerLocation
end
M.menuScene = function()
gV.currentScene = "menu"
end
M.settingsScene = function()
gV.currentScene = "settings"
end
M.creditsScene = function()
gV.currentScene = "credits"
end
M.switchScene = function()
composer.gotoScene( gV.currentScene, { time=800, effect="crossFade" } )
end
return M