What are the new ways of getting request_slot_count?

Place to get help with not working mods / modding interface.
sensenmann
Burner Inserter
Burner Inserter
Posts: 13
Joined: Tue Feb 28, 2017 5:04 pm
Contact:

What are the new ways of getting request_slot_count?

Post by sensenmann »

Removed LuaEntity::clear_request_slot(), get_request_slot() and set_request_slot() methods.
Removed LuaEntity::request_slot_count read.
What are the new ways of getting request_slot_count?

How do i migrate get_request_slot and set_request_slot in my mod to 2.0?

My code is

Code: Select all

			
for i = 1, entity.request_slot_count do
	local slot = entity.get_request_slot(i)
	if slot ~= nil and slot.name == "alien-hyper-module-" .. storage.currentmodulelevel[forceName] - 1 then
		entity.set_request_slot({ name = "alien-hyper-module-" .. storage.currentmodulelevel[forceName], count = slot.count }, i)
	end

	if settings.startup["alien-module-hyper-ammo-enabled"].value and slot ~= nil and slot.name == "alien-hyper-magazine-" .. storage.currentmodulelevel[forceName] - 1 then
		entity.set_request_slot({ name = "alien-hyper-magazine-" .. storage.currentmodulelevel[forceName], count = slot.count }, i)
	end
end
Koub
Global Moderator
Global Moderator
Posts: 7764
Joined: Fri May 30, 2014 8:54 am
Contact:

Re: What are the new ways of getting request_slot_count?

Post by Koub »

[Koub] Split from the release thread, and made it into its own thread in the modding help subforum
Koub - Please consider English is not my native language.
firebladed3
Burner Inserter
Burner Inserter
Posts: 8
Joined: Fri Jun 30, 2017 5:22 pm
Contact:

Re: What are the new ways of getting request_slot_count?

Post by firebladed3 »

This appears to require iterating through the LuaLogisticPoint.sections you can get from LuaControl.get_requester_point()
sensenmann
Burner Inserter
Burner Inserter
Posts: 13
Joined: Tue Feb 28, 2017 5:04 pm
Contact:

Re: What are the new ways of getting request_slot_count?

Post by sensenmann »

Thanks that did the trick.

Heres my code if someone wonders how it is done (no guarantee its bug-free ;)

Code: Select all

-- upgrade logistc requests
local logistics_point = entity.get_requester_point()
if logistics_point ~= nil then
	for i = 1, logistics_point.sections_count do
		local section = logistics_point.get_section(i)
		for ii = 1, section.filters_count do
			if section.get_slot(ii).value.name == "alien-hyper-module-" .. storage.currentmodulelevel[forceName] - 1 then
				local current_filter = section.get_slot(ii)
				section.set_slot(ii, { value = { name = "alien-hyper-module-" .. storage.currentmodulelevel[forceName], quality = current_filter.value.quality, comparator = current_filter.value.comparator },
									   min = current_filter.min,
									   max = current_filter.max })
			end
		end
	end
end
User avatar
Silari
Filter Inserter
Filter Inserter
Posts: 530
Joined: Sat Jan 27, 2018 10:04 pm
Contact:

Re: What are the new ways of getting request_slot_count?

Post by Silari »

I've had to look into this for Manual Logistics, and it looks like using the # operator on the filters property of the logistic point works if you just want the count.

Code: Select all

mylogpt = mychar.get_logistic_point(defines.logistic_member_index.character_requester)
log(#mylogpt.filters)
gives the output of 35, which is how many requests I have set on my character.

Filters also seems to work for what I need in general, since it outputs an array with every request with the name and count for each.

Code: Select all

{comparator = "=",
 count = 200,
 index = 35,
 name = "advanced-circuit",
 quality = "normal"},

For manipulating the requests, it does look like you need to iterate the sections for that.
Post Reply

Return to “Modding help”