Page 1 of 1
Search tile around player position
Posted: Tue Feb 21, 2017 6:49 am
by vtx
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.
Re: Search tile around player position
Posted: Tue Feb 21, 2017 7:50 am
by DaveMcW
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.
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
Posted: Tue Feb 21, 2017 8:07 am
by vtx
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.
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")))
Will display
Re: Search tile around player position
Posted: Tue Feb 21, 2017 8:10 am
by Nexela
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.
Re: Search tile around player position
Posted: Tue Feb 21, 2017 8:23 am
by vtx
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.
Re: Search tile around player position
Posted: Tue Feb 21, 2017 8:37 am
by Nexela
vtx 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.
You can use the log() function to print directly to the factorio-current log file
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
Posted: Tue Feb 21, 2017 8:49 am
by vtx
Thanks a lot for the help!