[Resolved] Identify floor/tile being mined name

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

[Resolved] Identify floor/tile being mined name

Post by TheSAguy »

Morning,

I'm trying to identify the name of the floor/tile I'm mining, but using my code below I'm only getting the name tile below the floor/tile I'm mining/picking up.

How should I adjust my code to give me the name of the tile being picked up vs. the tile underneath?

Code: Select all

local function Tile_Remove(event)
   

   local player = game.players[event.player_index]
   local robot = event.robot
   local surface = player and player.surface or robot.surface
   local position = event.positions

   for i, position in ipairs(position) do
      local currentTilename = surface.get_tile(position.x,position.y).name
      writeDebug(currentTilename) <-- My function that prints the name

   end   
         
end

local remove_events = {defines.events.on_player_mined_tile, defines.events.on_robot_mined_tile}
script.on_event(remove_events, Tile_Remove)

Thanks.
Last edited by TheSAguy on Wed May 10, 2017 1:46 am, edited 1 time in total.

321freddy
Fast Inserter
Fast Inserter
Posts: 125
Joined: Fri Sep 23, 2016 10:16 pm
Contact:

Re: Identify floor/tile being mined name

Post by 321freddy »

The events on_player_mined_tile and on_robot_mined_tile are fired AFTER the tile has been mined which is why you only get the name of the tile underneath.
Use on_player_mined_item and on_robot_mined instead. Here is an example:

Code: Select all

script.on_event(defines.events.on_player_mined_item, function(event)
     local player = game.players[event.player_index]
     local tile_name = event.item_stack.name
     local tile = game.item_prototypes[tile_name].place_as_tile_result

     if tile and player.mining_state.mining then
          local tile_position = player.mining_state.position
          game.print("Tile "..tile_name..", pos "..serpent.line(tile_position))
     end
end)
With robots use robot.position as the tile position.

EDIT: code fixed

TheSAguy
Smart Inserter
Smart Inserter
Posts: 1449
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Re: Identify floor/tile being mined name

Post by TheSAguy »

Thanks 321freddy, I'll give it a go!
P.S. Worked!

DeznekCZ
Burner Inserter
Burner Inserter
Posts: 11
Joined: Fri Sep 23, 2016 12:56 pm
Contact:

Re: Identify floor name while mining or placing

Post by DeznekCZ »

Hi 321freddy,

is nice solution but, i need the name know in every tick and every tick i don't have stack of tiles.

That looks like bigger problem in C++ code.

Thanks for answer

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Identify floor name while mining or placing

Post by eradicator »

DeznekCZ wrote:is nice solution but, i need the name know in every tick and every tick i don't have stack of tiles.
Not sure why you think you need to know a tiles name every tick...but that's quite easy. Tiles don't change unless an event is fired. So: Read tile name -> tile will have the same name forever or until an event is fired.

DeznekCZ
Burner Inserter
Burner Inserter
Posts: 11
Joined: Fri Sep 23, 2016 12:56 pm
Contact:

Re: [Resolved] Identify floor/tile being mined name

Post by DeznekCZ »


Post Reply

Return to “Modding help”