Strange error in F mod - Can't solve

Place to get help with not working mods / modding interface.
User avatar
Kayanor
Global Moderator
Global Moderator
Posts: 566
Joined: Sat May 10, 2014 7:20 am
Contact:

Strange error in F mod - Can't solve

Post by Kayanor »

Hello there,
Im here to ask, if someone can help me out with F mod.

As you may know I'm contiuing this mod for Factorio 0.11 inofficially but nucleo found a little thing I can't fix.
It is connected to the Underground mining drills, if you place one, this message pops up:
Image
Where I'm stucking at is the attempt to index field '?' (a nil value).

If you want to get to the download to take a look at it, it's here: viewtopic.php?f=45&t=390&start=580#p58994
On the page's bottom you can find the original thread from nucleo.

Thank you in advance!
Former moderator
User avatar
L0771
Filter Inserter
Filter Inserter
Posts: 516
Joined: Tue Jan 14, 2014 1:51 pm
Contact:

Re: Strange error in F mod - Can't solve

Post by L0771 »

I don't know, maybe with this, but i think it don't must give a error asking if is nil.

Code: Select all

if not glob.stonepilescount then
	glob.stonepiles={}
	glob.stonepilescount=0
end
User avatar
Kayanor
Global Moderator
Global Moderator
Posts: 566
Joined: Sat May 10, 2014 7:20 am
Contact:

Re: Strange error in F mod - Can't solve

Post by Kayanor »

L0771 wrote:I don't know, maybe with this, but i think it don't must give a error asking if is nil.

Code: Select all

if not glob.stonepilescount then
	glob.stonepiles={}
	glob.stonepilescount=0
end
That changed like nothing, it's just another expression and the Stone piles aren't connected to the Underground mining drills. I think it is located directly in their part of the code.
Former moderator
Rahjital
Filter Inserter
Filter Inserter
Posts: 435
Joined: Thu May 29, 2014 10:44 am
Contact:

Re: Strange error in F mod - Can't solve

Post by Rahjital »

It's line 821 in control.lua, which is this:

Code: Select all

local rx1=(holes[1].position.x-(holes[1].position.x)%32)/32
It seems the holes table is empty, so holes[1] is nil. The holes table is initialized on line 819:

Code: Select all

local holes=game.findentitiesfiltered{area={{event.createdentity.position.x-0.1,event.createdentity.position.y-0.1},{event.createdentity.position.x,event.createdentity.position.y}},name="holes"}
It appears the problem is that game.findentitiesfiltered finds nothing, which crashes the rest of the code.
User avatar
L0771
Filter Inserter
Filter Inserter
Posts: 516
Joined: Tue Jan 14, 2014 1:51 pm
Contact:

Re: Strange error in F mod - Can't solve

Post by L0771 »

:lol: i've download other version XD
Sorry :oops:
User avatar
Kayanor
Global Moderator
Global Moderator
Posts: 566
Joined: Sat May 10, 2014 7:20 am
Contact:

Re: Strange error in F mod - Can't solve

Post by Kayanor »

Rahjital wrote:It appears the problem is that game.findentitiesfiltered finds nothing, which crashes the rest of the code.
Thanks, now I know where the problem is.
Could it be connected with that position-definition below?

Code: Select all

{event.createdentity.position.x-0.1,event.createdentity.position.y-0.1},{event.createdentity.position.x,event.createdentity.position.y}
Former moderator
User avatar
L0771
Filter Inserter
Filter Inserter
Posts: 516
Joined: Tue Jan 14, 2014 1:51 pm
Contact:

Re: Strange error in F mod - Can't solve

Post by L0771 »

try with this

Code: Select all

		if #holes > 0 then
			local rx1=(holes[1].position.x-(holes[1].position.x)%32)/32
			local ry1=(holes[1].position.y-(holes[1].position.y)%32)/32
			local rx2=holes[1].position.x%32
			local ry2=holes[1].position.y%32
			
			if glob.undergroundores==nil then
				glob.undergroundores={}
			end
			if glob.undergroundores[rx1]==nil then
				glob.undergroundores[rx1]={}
			end
			if glob.undergroundores[rx1]==nil then
				glob.undergroundores[rx1]={}
			end
			if glob.undergroundores[rx1][ry1]==nil then
				glob.undergroundores[rx1][ry1]={}
			end
			if glob.undergroundores[rx1][ry1].richness==nil then
				glob.undergroundores[rx1][ry1].richness={}
			end
			if glob.undergroundores[rx1][ry1].richness[rx2]==nil then
				glob.undergroundores[rx1][ry1].richness[rx2]={}
			end
			if glob.undergroundores[rx1][ry1].richness[rx2][ry2]==nil then
				glob.undergroundores[rx1][ry1].richness[rx2][ry2]=math.random(5)
			end
			local richness = glob.undergroundores[rx1][ry1].richness[rx2][ry2]
			table.insert(glob.umd, {entity=event.createdentity, rich=richness})

			if richness==1 then
				game.player.print("Found "..glob.undergroundores[rx1][ry1].resource.." with a awful richness")
			elseif richness==2 then
				game.player.print("Found "..glob.undergroundores[rx1][ry1].resource.." with a bad richness")
			elseif richness==3 then
				game.player.print("Found "..glob.undergroundores[rx1][ry1].resource.." with a medium richness")
			elseif richness==4 then
				game.player.print("Found "..glob.undergroundores[rx1][ry1].resource.." with a good richness")
			elseif richness==5 then
				game.player.print("Found "..glob.undergroundores[rx1][ry1].resource.." with a premium richness")
			end
		else
			game.player.print("no hay hole.")
		end
User avatar
Kayanor
Global Moderator
Global Moderator
Posts: 566
Joined: Sat May 10, 2014 7:20 am
Contact:

Re: Strange error in F mod - Can't solve

Post by Kayanor »

Code: Select all

if #holes > 0 then
That seems to be given never.
In Factorio's opinion, there is no hole although I can see it AND the Underground mining drill can't be placed without it.

Think about it, the code worked properly until one of the last two updates.
Former moderator
User avatar
L0771
Filter Inserter
Filter Inserter
Posts: 516
Joined: Tue Jan 14, 2014 1:51 pm
Contact:

Re: Strange error in F mod - Can't solve

Post by L0771 »

Kajanor wrote:

Code: Select all

if #holes > 0 then
That seems to be given never.
why not?
try with this to find entities.

Code: Select all

local positionCreated = event.createdentity.position
local holes=game.findentitiesfiltered{area={{x = math.ceil(positionCreated.x),math.ceil(positionCreated.y)},{math.floor(positionCreated.x),math.floor(positionCreated.y)}},name="holes"}
But in umd have property resource_categories = {"hole"}, the umd need be constructed over a hole.
Rahjital
Filter Inserter
Filter Inserter
Posts: 435
Joined: Thu May 29, 2014 10:44 am
Contact:

Re: Strange error in F mod - Can't solve

Post by Rahjital »

Kajanor wrote:Thanks, now I know where the problem is.
Could it be connected with that position-definition below?

Code: Select all

{event.createdentity.position.x-0.1,event.createdentity.position.y-0.1},{event.createdentity.position.x,event.createdentity.position.y}
You could try making the search area larger. As far as I know, there was some change in how entities are positioned, so it's probably searching half a tile away from the hole and not finding anything.

However, there's a much simpler solution: instead of searching for holes, just use the drill's position. This is simpler, faster and more reliable, and I'm not quite sure why the mod author didn't do it that way in the first place. Simply replace this:

Code: Select all

local holes=game.findentitiesfiltered{area={{event.createdentity.position.x-0.1,event.createdentity.position.y-0.1},{event.createdentity.position.x,event.createdentity.position.y}},name="holes"}
		
local rx1=(holes[1].position.x-(holes[1].position.x)%32)/32
local ry1=(holes[1].position.y-(holes[1].position.y)%32)/32
local rx2=holes[1].position.x%32
local ry2=holes[1].position.y%32
with this:

Code: Select all

local rx1=(event.createdentity.position.x-(event.createdentity.position.x)%32)/32
local ry1=(event.createdentity.position.y-(event.createdentity.position.y)%32)/32
local rx2=event.createdentity.position.x%32
local ry2=event.createdentity.position.y%32
It's still not the most efficient piece of code, but I'm trying to keep with the original "style". The mod could use a total rewrite.
User avatar
Kayanor
Global Moderator
Global Moderator
Posts: 566
Joined: Sat May 10, 2014 7:20 am
Contact:

Re: Strange error in F mod - Can't solve

Post by Kayanor »

I've tested both codes ingame right now :D

L0771, that idea to let the game find the hole under the drill is great, the only problem is, the new findentitiesfiltered is returning "#-1" (if I read the error message right).
I don't know where this is coming from because I'm very new to Lua, but the code seems legit ;)

Rahjital, as I understood, your code isn't searching for a hole do "mine", it directly uses the position of the UMD. That is removing the buggy seaching-algorithm, what makes it working again :D

I really thank you both for your efforts, you will get named in the next inofficial release post :)
Rahjital wrote:The mod could use a total rewrite.
Ficolas is working on it. (I hope so)
Former moderator
Post Reply

Return to “Modding help”