Skip to content

Accessing an object #29

Answered by gilzoide
Mikhail666999 asked this question in Q&A
Nov 19, 2022 · 3 comments · 2 replies
Discussion options

You must be logged in to vote

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 calling get_node("lof") (docs here).

So in Lua all you need to do is set the variable inside the _ready method using get_node, which is exactly what GDScript does in your snippet:

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

Replies: 3 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@TrainzMarcel
Comment options

@gilzoide
Comment options

Answer selected by Mikhail666999
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants