How can I pass through a type in a function, without wanting the type itself?

I am making an “Enemy” class for my game. And there is a bunch of variables packed in a type called “Enemy”. The idea is that a module script called “Register” will register every enemy I create, once. That way every other script can access it and create a new instance of the Enemy.

I was wondering how I could make it so it pops up every variable underneath Enemy for the function to be ran. I’m a little confused and I might be going about this entirely wrong. Any suggestion will help. I’m aware that I could just manually put in every single variable but theres 37 instead of the 3 shown.

This is not the full extent of the code right now, but just a demo for this problem.

type EnemyName = string
export type Enemy = {
	-- Display
	Name: EnemyName,
	Model: Model,
	Description: string,
}

type Hashmap<K,V> = {[K]:V}
type Enemies = Hashmap<EnemyName, Enemy>

local Enemy = {}
Enemy.__index = Enemy

local Enemies: Enemies = {}

function Enemy.Register(Name) -- I need to pass through every variable under the type Enemy.
	local newEnemy: Enemy = {}
	
	return setmetatable(newEnemy, Enemy)
end

return Enemy

Of course I figure it out right as soon as I post about it asking for help. This is my solution:

function Enemy.Register(properties: Enemy)
	local newEnemy: Enemy = {} --ignore error
	
	for key, value in pairs(properties) do
		newEnemy[key] = value
	end
	
	Enemies[newEnemy.Name] = newEnemy
	return setmetatable(newEnemy, Enemy)
end
1 Like