From the lua api
game.player.print(tostring(game.player.surface.get_tile(1, 1).collides_with("player-layer")))
To make it work I remove game :
player.print(tostring(player.surface.get_tile(1, 1).collides_with("player-layer")))
When I use something like 2,2 and higher it didn't work. What I do wrong ? To be more accurate it only work once I can't use it more than one time.
Search tile around player position
Re: Search tile around player position
If you call the function with numbers, it uses map position.
To check next to the player, call it with the player position and an offset.
To check next to the player, call it with the player position and an offset.
Code: Select all
/c game.player.print(tostring(game.player.surface.get_tile(game.player.position.x+1, game.player.position.y).collides_with("player-layer"))) Re: Search tile around player position
Thanks for the offset hint.
Sorry I forget to mention I did that in a mod environement.
More specific inside scenario file in on_player_created event.
Still on testing how lua work before dive in code itself.
Will display
Sorry I forget to mention I did that in a mod environement.
More specific inside scenario file in on_player_created event.
Still on testing how lua work before dive in code itself.
Code: Select all
player.print("1,1")
player.print(tostring(player.surface.get_tile(player.position.x+1,player.position.y+1 ).collides_with("player-layer")))
player.print("2,2")
player.print(tostring(player.surface.get_tile(player.position.x+2,player.position.y+2 ).collides_with("player-layer")))
player.print("3,3")
player.print(tostring(player.surface.get_tile(player.position.x+3,player.position.y+3 ).collides_with("player-layer")))
player.print("4,4")
player.print(tostring(player.surface.get_tile(player.position.x+4,player.position.y+4 ).collides_with("player-layer")))
player.print("5,5")
player.print(tostring(player.surface.get_tile(player.position.x+5,player.position.y+5 ).collides_with("player-layer")))
player.print("6,6")
player.print(tostring(player.surface.get_tile(player.position.x+6,player.position.y+6 ).collides_with("player-layer")))
Code: Select all
1,1
false
2,2
3,3
4,4
5,5
6,6
Re: Search tile around player position
You are coming up against spam protection
Since "false" would be printed x number of times in a period it only shows once. However the code does run correctly.
Since "false" would be printed x number of times in a period it only shows once. However the code does run correctly.
Re: Search tile around player position
Oh my god!!! Thanks !
I didn't know there spam protection for print. I'll dive directly into code then.
Is there some tool to help debug code or is just code and hope for the best ?
I know the F4-F7 but not that it'll bring me the information I want or I oversee something.
I didn't know there spam protection for print. I'll dive directly into code then.
Is there some tool to help debug code or is just code and hope for the best ?
I know the F4-F7 but not that it'll bring me the information I want or I oversee something.
Re: Search tile around player position
You can use the log() function to print directly to the factorio-current log filevtx wrote:Oh my god!!! Thanks !
I didn't know there spam protection for print. I'll dive directly into code then.
Is there some tool to help debug code or is just code and hope for the best ?
I know the F4-F7 but not that it'll bring me the information I want or I oversee something.
or
game.write_file() to output to a file in script-output directory
Both of those options are not affected by any spam protection
Re: Search tile around player position
Thanks a lot for the help!

