[SOLVED]on_player_built_tile error

Place to get help with not working mods / modding interface.
CruWiT
Inserter
Inserter
Posts: 23
Joined: Wed Apr 17, 2019 6:22 pm
Contact:

[SOLVED]on_player_built_tile error

Post by CruWiT »

I want create event when build a tile like stone-path and destroy decoratives. I use this links;
https://lua-api.factorio.com/latest/eve ... built_tile
https://lua-api.factorio.com/latest/Lua ... ecoratives
this is my control.lua;

Code: Select all

script.on_event(defines.events.on_player_built_tile, function(event)
	local surface = game.surfaces[event.surface_index]
	local tiles = event.tiles
	
	for _,tile in pairs(tiles) do
	local tile_position = surface.get_tile(tile.position.x, tile.position.y)
	surface.destroy_decoratives{area={{-0.5, -0.5}, {0.5, 0.5}}, position=tile_position}
	end
end)
and I have this error;

The mod Decorative Removal caused a non-recoverable error.
Please report this error to the mod author.

Error while running event Decorative-Removal::on_player_built_tile (ID 45)
LuaTile doesn't contain key x.
stack traceback:
[C]: in function 'destroy_decoratives'
__Decorative-Removal__/control.lua:7: in function <__Decorative-Removal__/control.lua:1>
stack traceback:
[C]: in ?
[C]: in function 'destroy_decoratives'
__Decorative-Removal__/control.lua:7: in function <__Decorative-Removal__/control.lua:1>
Last edited by CruWiT on Tue Aug 25, 2020 8:06 pm, edited 1 time in total.
User avatar
Klonan
Factorio Staff
Factorio Staff
Posts: 5304
Joined: Sun Jan 11, 2015 2:09 pm
Contact:

Re: on_player_built_tile error

Post by Klonan »

Code: Select all

	local tile_position = surface.get_tile(tile.position.x, tile.position.y)
should be

Code: Select all

	local tile_position = surface.get_tile(tile.position.x, tile.position.y).position
	
But also, why use tile_position, when you are looking up the tile from tile.position?
CruWiT
Inserter
Inserter
Posts: 23
Joined: Wed Apr 17, 2019 6:22 pm
Contact:

Re: on_player_built_tile error

Post by CruWiT »

Klonan wrote: Tue Aug 25, 2020 12:03 pm

Code: Select all

	local tile_position = surface.get_tile(tile.position.x, tile.position.y)
should be

Code: Select all

	local tile_position = surface.get_tile(tile.position.x, tile.position.y).position
	
But also, why use tile_position, when you are looking up the tile from tile.position?
Error is gone thanks. But decoratives on tiles doesn't remove when place stone-path.
mrvn
Smart Inserter
Smart Inserter
Posts: 5969
Joined: Mon Sep 05, 2016 9:10 am
Contact:

Re: on_player_built_tile error

Post by mrvn »

Is the tiles position you get the corner or the center of the tile? This would affect your area.

And maybe make the area a bit bigger so decorations that are outside the tile but overlap it also get removed.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: on_player_built_tile error

Post by eradicator »

Destroying decoratives doesn't require control stage code. You can just change the prototype.
First mod portal search hit: https://mods.factorio.com/mod/CleanedConcrete
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
CruWiT
Inserter
Inserter
Posts: 23
Joined: Wed Apr 17, 2019 6:22 pm
Contact:

Re: on_player_built_tile error

Post by CruWiT »

mrvn wrote: Tue Aug 25, 2020 2:49 pm Is the tiles position you get the corner or the center of the tile? This would affect your area.

And maybe make the area a bit bigger so decorations that are outside the tile but overlap it also get removed.
I try bigger area but doesn't change anything.
CruWiT
Inserter
Inserter
Posts: 23
Joined: Wed Apr 17, 2019 6:22 pm
Contact:

Re: on_player_built_tile error

Post by CruWiT »

eradicator wrote: Tue Aug 25, 2020 3:42 pm Destroying decoratives doesn't require control stage code. You can just change the prototype.
First mod portal search hit: https://mods.factorio.com/mod/CleanedConcrete
I know thats mod you right but I want create runtime settings for my mod. because sometimes I want on/off destroy decoratives.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: on_player_built_tile error

Post by eradicator »

TilePosition

Coordinates of a tile in a chunk on a LuaSurface where each integer x/y represents a different tile. This uses the same format as Position except it rounds any x/y down to whole numbers.
Also you need to specify an absolute area on the surface. Not a bounding box relative to the tile.

Code: Select all

/c 

local function show(args)
  rendering.draw_rectangle{
    color = {r=1},
    width = 4,
    filled = false,
    left_top = args.area[1],
    right_bottom = args.area[2],
    surface = args.surface_index,
    time_to_live = 120,
    }
  end

script.on_event({
  defines.events.on_robot_built_tile,
  defines.events.on_player_built_tile,
  },function(e)    
    local surface = game.surfaces[e.surface_index]
    for _,TileAndPosition in pairs(e.tiles) do
      local pos = TileAndPosition.position
      local area={{pos.x,pos.y},{pos.x+1,pos.y+1}}
      surface.destroy_decoratives{area=area}
      show{area=area,surface_index=e.surface_index}
      end  
    end)
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
CruWiT
Inserter
Inserter
Posts: 23
Joined: Wed Apr 17, 2019 6:22 pm
Contact:

Re: on_player_built_tile error

Post by CruWiT »

eradicator wrote: Tue Aug 25, 2020 4:05 pm
TilePosition

Coordinates of a tile in a chunk on a LuaSurface where each integer x/y represents a different tile. This uses the same format as Position except it rounds any x/y down to whole numbers.
Also you need to specify an absolute area on the surface. Not a bounding box relative to the tile.

Code: Select all

/c 

local function show(args)
  rendering.draw_rectangle{
    color = {r=1},
    width = 4,
    filled = false,
    left_top = args.area[1],
    right_bottom = args.area[2],
    surface = args.surface_index,
    time_to_live = 120,
    }
  end

script.on_event({
  defines.events.on_robot_built_tile,
  defines.events.on_player_built_tile,
  },function(e)    
    local surface = game.surfaces[e.surface_index]
    for _,TileAndPosition in pairs(e.tiles) do
      local pos = TileAndPosition.position
      local area={{pos.x,pos.y},{pos.x+1,pos.y+1}}
      surface.destroy_decoratives{area=area}
      show{area=area,surface_index=e.surface_index}
      end  
    end)
it's work now thanks.
Post Reply

Return to “Modding help”