Page 1 of 1

Report an error: 'allowed_module_categorys' is invalid

Posted: Sun Mar 30, 2025 5:33 am
by sdgmlj
Game version:2.0.42

Code: Select all

local function get_module_names(name)          --name = "assembling-machine-3"
	local names = {}
	local cs = prototypes.entity[name].allowed_module_categories
	local items = prototypes.get_item_filtered({{filter = "type", type = "module"}})
	for im,item in pairs(items) do 
		local c = item.category
		if cs[c]
		then table.insert(names,im)
		end
	end
	return names
end
The error message is: cs is nil

Re: Report an error: 'allowed_module_categorys' is invalid

Posted: Sun Mar 30, 2025 5:47 am
by Rseding91
Sorry but I do not understand this report. Please explain better what is going wrong and what you expect to be happening instead.

Re: Report an error: 'allowed_module_categorys' is invalid

Posted: Sun Mar 30, 2025 5:50 am
by sdgmlj
Rseding91 wrote: Sun Mar 30, 2025 5:47 am Sorry but I do not understand this report. Please explain better what is going wrong and what you expect to be happening instead.
prototypes.entity[name].allowed_module_categories
We should get an array, but the result it gives is empty

Re: Report an error: 'allowed_module_categorys' is invalid

Posted: Sun Mar 30, 2025 6:17 am
by Rseding91
https://lua-api.factorio.com/latest/cla ... categories Indicates its optional and if not defined for an entity will return nil. So this is working correctly.

Re: Report an error: 'allowed_module_categorys' is invalid

Posted: Sun Mar 30, 2025 6:24 am
by sdgmlj
Rseding91 wrote: Sun Mar 30, 2025 6:17 am https://lua-api.factorio.com/latest/cla ... categories Indicates its optional and if not defined for an entity will return nil. So this is working correctly.
Can I understand it this way?
This one is prepared for mods, as all default prototypes in the game have not been added, so it is invalid.