Accessing an object #29
-
Hello, how to access the object? and in lua how? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Hi @Mikhail666999 ! So in Lua all you need to do is set the variable inside the local MyClass = {
extends = 'Node',
}
function MyClass:_ready()
-- `get_node` must be called from `self`, as it is a method from the Node class
self.Lof = self:get_node("lof")
end
-- ...
return MyClass |
Beta Was this translation helpful? Give feedback.
-
understood thanks) |
Beta Was this translation helpful? Give feedback.
-
Hey folks, so I've added a From GDScript to Lua document to the repo! It's far from a comprehensive list, but it's a start. Throughout the following weeks (most likely weekends, most likely 2023 only) I want to improve this document and create any others that might make sense =] Thanks again for your feedbacks, feel free to keep in touch! |
Beta Was this translation helpful? Give feedback.
Hi @Mikhail666999 !
When you use the
onready
keyword for setting a script variable, it's the same as setting it inside the script's_ready
method (docs here).Also, the literal
$lof
is the same as callingget_node("lof")
(docs here).So in Lua all you need to do is set the variable inside the
_ready
method usingget_node
, which is exactly what GDScript does in your snippet: