[Resolved] Position Help

Place to get help with not working mods / modding interface.
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1456
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

[Resolved] Position Help

Post by TheSAguy »

Can someone please tell me why my two positions in the create and remove functions below don't match.

Create Code:

Code: Select all


local function On_Built(event)

local entity = event.created_entity


	--------- Battle Marker Built
	if entity and entity.name == "battle_marker" then

			writeDebug("Battle Marker Built")
			local surface = event.created_entity.surface
			local force = event.created_entity.force
			local pos = event.created_entity.position
			local dir = event.created_entity.direction
						
			for i=1, 5000 do
				surface.create_entity{name = "battle_marker_hidden", position = pos, force = force, direction = dir}
				writeDebug("Hidden Marker built: " ..i)
			end
	
	end
	
	
end



Remove Code:

Code: Select all

local function On_Remove(event)	
	--------- Remove Battle Marker
	if (event.entity.name == "battle_marker") then

			local surface = event.entity.surface
			local pos = event.entity.position
			
			for i=1, 5000 do
				if surface.find_entity("battle_marker_hidden", pos) then
					surface.find_entity("battle_marker_hidden", pos).destroy()
					writeDebug("Hidden Marker Removed: " ..i)
				else
					writeDebug("Hidden Marker not found")				
				end
			end

	end
	
end
It give me the message: "Hidden Marker not found", vs."Hidden Marker Removed:"
I can't figure out what I'm doing wrong to get the two positions to match.

Thanks.
Last edited by TheSAguy on Fri Jun 02, 2017 4:54 am, edited 1 time in total.
Choumiko
Smart Inserter
Smart Inserter
Posts: 1352
Joined: Fri Mar 21, 2014 10:51 pm
Contact:

Re: Position Help

Post by Choumiko »

Try printing the positions, could be some float issue if they are placeable offgrid. Worst case use find_entities_filtered with an area with 0.1 radius.
Nexela
Smart Inserter
Smart Inserter
Posts: 1828
Joined: Wed May 25, 2016 11:09 am
Contact:

Re: Position Help

Post by Nexela »

Find entity position doesn't return entities with no collision box also
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1456
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Position Help

Post by TheSAguy »

Thanks to you both.
I was fixing it using the area search, but it was the no collision box causing the problem.
Thanks again!
Post Reply

Return to “Modding help”