What am I doing wrong?

Hi, I can’t seem to get past an error I keep getting.  The error says: … attempt to index field ‘playerManagerFunction’ (a function value).  The line in question is this one:

local playerInit = function() playerManager.playerManagerFunction.setStartLine(); end 

Here’s how this line looks in my code: 

---------------------------------------------------------------------------------- -- -- s01.lua -- ---------------------------------------------------------------------------------- local storyboard = require( "storyboard" ) local scene = storyboard.newScene() ---------------------------------------------------------------------------------- local playerManager = require("scripts.managers.PlayerManager") -- -- NOTE: -- -- Code outside of listener functions (below) will only be executed once, -- unless storyboard.removeScene() is called. -- --------------------------------------------------------------------------------- --------------------------------------------------------------------------------- -- BEGINNING OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- BG = display.newImage("images/backgrounds/Background 04.png") BG.isVisible = false local playerInit = function() playerManager.playerManagerFunction.setStartLine(); end playerInit() -- Called when the scene's view does not exist: function scene:createScene( event ) local group = self.view ----------------------------------------------------------------------------- -- CREATE display objects and add them to 'group' here. -- Example use-case: Restore 'group' from previously saved state. ----------------------------------------------------------------------------- end

Here is my PlayerManager.lua file:

-- define a local table to store all references to functions/variables local M = {} -- functions are now local: local playerManagerFunction = function() local factoryName = 'images.characters.ShPlayer02' local factory = \_G.factoryManager.getFactory(factoryName); local o = display.newGroup() o.setStartLine = function() player.isVisible = true player.x = \_G.W/2 player.y = 1024+200 player.setAngle('moveUp',true) player.lastX = player.x; transition.to (player, {time = 700, delay = 0, y = 1000, onComplete=function() player.setAngle('stopUp'); end} ) end -- constructor o.init = function() end o.init() return o; end M.playerManagerFunction = playerManagerFunction -- Finally, return the table to be used locally elsewhere return M

I’ve been at this for hours, so any help would be greatly appreciated.  Thanks!

You are trying to call a function on an object which is returned by another function. What you need to do is call the playManagerFunction() and then call the setStartLine() function on the returned object. You are also calling the functions with a ‘.’ when I think you should be using ‘:’

The way to do this on a single line is like this:

local playerInit = function()     playerManager:playerManagerFunction():setStartLine() end

Try that and let me know what you get.

You are trying to call a function on an object which is returned by another function. What you need to do is call the playManagerFunction() and then call the setStartLine() function on the returned object. You are also calling the functions with a ‘.’ when I think you should be using ‘:’

The way to do this on a single line is like this:

local playerInit = function()     playerManager:playerManagerFunction():setStartLine() end

Try that and let me know what you get.