引用Lua中的父类(Corona)

clu*_*ua7 0 lua coronasdk

在我的game.lua文件中我有这个:

function new()

    local obj = display.newGroup();

    currentLevel = Level.new(1);
    currentLevel.game = obj; //also tried currentLevel.game = self;

    function obj:replay()
            print("game - replay")
    end

    return obj;

end
Run Code Online (Sandbox Code Playgroud)

在Level lua文件中,我尝试在game.lua中调用重播函数:

game = {};
...
game:replay();
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误:尝试调用方法'重放'(一个零值)

如何在level.lua中保留对游戏文件的引用?

sbk*_*sbk 7

难道你的意思game = new(),而不是game = {}?如果你game{}它创建那么它是一个空表.