Skip to content
Discussion options

You must be logged in to vote

The second question is, how do I create an instance of a new class from another class?

Specifying the class_name should be working, but it seems to not be working at all. That's a bug, I'll try fixing that later.
In any case, you can load the LuaScript using ResourceLoader and use it instead:

local init_game = {
	extends = Node2D,
}

-- Here's the loading part.
-- This is just like using GDScript's `load` function
local MyClass = ResourceLoader:load("res://MyClass.lua")

function init_game:_ready()
	-- Now it should be working
	local t = MyClass:new()
	self:add_child(t)
end
return init_game

Replies: 1 comment 4 replies

Comment options

You must be logged in to vote
4 replies
@whileload
Comment options

@gilzoide
Comment options

@whileload
Comment options

@gilzoide
Comment options

Answer selected by whileload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants