Closed Alikae closed 2 years ago
Hi, it looks like you may be calling the method incorrectly. I see you're using dot notation - e.g. parent.test()
in your Lua file. For Lua "objects" you should actually use a colon, like so parent:test()
. This will automatically pass in self
.
In essence, parent.test
would look for a class wide method whereas parent:test
would look for an instance method
Thanks. Look like I need to dive a little more in Lua. :pray:
Yeah, Lua is a little bit different than most programming languages. The next thing I want/need to do is a document like "From GDScript to Lua" showing these differences. Sorry that it isn't in place yet.
Not related, but if want, you can make highlighted code blocks with triple backticks and the language name.
For example, writing:
```gdscript
extends Node
func _ready():
var lua_script = load("res://LuaTest.lua")
lua_script.ltest(self)
func test():
print('It worked !')`
shows like
```gdscript
extends Node
func _ready():
var lua_script = load("res://LuaTest.lua")
lua_script.ltest(self)
func test():
print('It worked !')`
Hi @gilzoide.
Firstly, I would like to thank you for your work.
While trying to call a GDScript method from a Lua script, the owner of the method is not passed as first argument and need to be given manually.
Sample Code:
Test.gd:
LuaTest.lua:
Corresponding error:
E 0:00:00.490 test: attempt to index local 'o' (a nil value)
Is there something I missed on how it's supposed to work ? Thanks by advance,