Hello all. I was experimenting with the idea of creating multiple character lua files. Then require only the character file the player is using at game time. This would make it possible for my users to select from multiple saved characters without using up memory at game time. The code for it was working fine and then as I was tinkering it broke. Below is the runtime error I keep getting.
I am not too used to the debugging process yet, but it appears I have some sort of scope issue because of an unexpected nil value. I checked each page I am working with and they all appear to be written correctly to my own knowledge. I am not using any system variables by mistake that I could find. All variables are spelled and capped correctly, that I can tell.
Here is some code snippets. If you need to see more, please let me know:
globalVariables.lua
local M = {}
M.currentLevel = 1
M.currentPlayerType = 1
return M
player1.lua
local M = {}
M.mainSprites =
{ --Expand to edit Main Character Sprites
frames =
{
--Walk East
{ -- 1) Walk-E1
x = 0,
y = 0,
width = 36,
height = 52
},
--etc..
{ -- 55) Crouch-3
x = 72,
y = 312,
width = 36,
height = 52
}
}
}
M.mainSheet = graphics.newImageSheet( "sprites/SS-charMain.png", M.mainSprites )
return M
game.lua
--Use Composer
local composer = require( "composer" )
--Use Psudo-global modulation
local gV = require( "globalVariables" )
--Set player type
local pT = require( "player1" )
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()"
-- -----------------------------------------------------------------------------------
-- Initialize variables
--Actors
local player
-- -----------------------------------------------------------------------------------
-- Scene event functions
-- -----------------------------------------------------------------------------------
-- create()
function scene:create( event )
local sceneGroup = self.view
-- Code here runs when the scene is first created but has not yet appeared on screen
-- Set up display groups
backGroup = display.newGroup() -- Display group for the background image
sceneGroup:insert( backGroup ) -- Insert into the scene's view group
mainGroup = display.newGroup() -- Display group for the ship, asteroids, lasers, etc.
sceneGroup:insert( mainGroup ) -- Insert into the scene's view group
-- Load the player
player = display.newImageRect( mainGroup, pT.MainSheet, 1, 36, 52 )
player.x = display.contentCenterX --HERE is where the problem is happening
player.y = display.contentCenterY
player.myName = "player"
local function endGame()
composer.gotoScene( "menu", { time=800, effect="crossFade" } )
end
-- Load Listeners
player:addEventListener( "tap", endGame )
end
--etc.
return scene