Director class error: module join_game must have a new function

Hi, 

I have encountered this type of error when changing scenes using director. I have 3 scenes. Here are the sample flow:

join_game.lua:

module(“join_game”, package.seeall)

local M = {}

local function new()

    print “join_game.lua”

    local mainGroup = display.newGroup()

    function createPlayerId(event)

                director.changeScene(“set_up2”, “flip”)

    end

    return mainGroup

end

M.new = new

return M

search_game.lua:

module(“join_game”, package.seeall)

module(“search_game”, package.seeall)

local M = {}

local function new()

    print “search_game.lua”

    local mainGroup = display.newGroup()

   -------- create button function --------------

    function searchNowBtnPress(event)

            gameKeyword = searchField.text --searchField.text

            print (“text2”)

            print (gameKeyword)

            native.setKeyboardFocus( nil )

            audio.stop( menu_audio_play )

            local button_audio = audio.loadSound(“audio/clickButton_audio.mp3”)

            local button_audio_play = audio.play(button_audio, {channel=2, loops=0, fadein=0})

            director.changeScene(“search_result”, “crossfade”)

            return true

    end

    local function cancelBtnPress(event)

        native.setKeyboardFocus( nil )

        audio.stop( menu_audio_play )

        local button_audio = audio.loadSound(“audio/clickButton_audio.mp3”)

        local button_audio_play = audio.play(button_audio, {channel=2, loops=0, fadein=0})

        director.changeScene(“join_game”, “overFromTop”)

        audio.stop( button_audio_play )

        return true

    end

    return mainGroup

end

M.new = new

return M

search_result.lua:

module(“search_game”, package.seeall)

module(“search_result”, package.seeall)

local M = {}

local function new()


    --------- *** Button Functions *** ---------

    --------------------------------------------

    local function backBtnPress(event)

        director.changeScene(“search_game”, “overFromLeft”)

        return true

    end

    return mainGroup

end

M.new = new

return M

The changing of scenes works fine in this scenarios:

1. join_game – > search_game --> search_result (this is the main flow of my app)

  1. join_game – > search_game --> join_game

3. join_game -->search_game --> search_result --> search_game

But i got an error when:

 join_game -->search_game --> search_result --> search_game -->join_game

The error is: module ‘join_game’ must have a new() function

I have just posted some code snippets which is part of the director:changescene. The whole lua pages contain long codes.

Thanks.