Skip to content

LuaScriptException: [string "chunk"]:3: attempt to index a global 'Test' (a nil value) #20

@ZachHofmeister

Description

@ZachHofmeister

I'm having a problem accessing a function from a C# script through lua. This is the error given when the Lua script is run. Here is the function that runs the lua script:

`void RunPlayerScript () {
if (fileManager.activeFile != "") {
source = File.ReadAllText (Application.persistentDataPath + "/" + fileManager.activeFile + ".lua");

        env = new Lua ();
        env.LoadCLRPackage ();
        
        try {
            env.DoString (source);
        } catch (NLua.Exceptions.LuaException e) {
            Debug.LogError (FormatException (e), gameObject);
        }
        //Call ("");
    }
}`

Here is the Lua script being run:

import 'Piloting.Navigation'

Navigation.Test()

And here is the script containing the function being run from the Lua:

using UnityEngine;

namespace Piloting.Navigation {
    public static class Navigation {
        public static void Test () {
            Debug.Log ("Hello World!");
        }
    }
}

Anyone have any idea what is going wrong? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions