How do I check a tile that has been changed?

0 favourites
  • 11 posts
From the Asset Store
slide the tiles to fill the board.60 awesome levels.
  • Hi all,

    My player has the ability to modify the tilemap. For example they can use the Hoe tool to change the tile from grass (TileID:0) to dirt (TileID:1282). And this works just fine, switching the tile successfully.

    Once they change grass to dirt, the next step is for them to be able to water that tile, but the watering can should only work on dirt tiles. So what I am trying to do is check that the tileID underneath my aimer (used for targeting) is equal to TileID:1282 and if so they can water the tile. For this I am trying to use the "Compare tile at" action:

    Compare tile at X: Tilemap.PositionToTileX(Aimer.X)

    Compare tile at Y: Tilemap.PositionToTileX(Aimer.Y)

    = Equal to

    Tile ID: 1282

    But this check never returns successfully, event though the tile underneath the aimer is a dirt tile (TileID:1282). What's odd is that if I set it to check for the grass tile (TileID:0), it does work. So I think that even though the tile image has been changed from grass to dirt, the tileID isn't actually being updated.

    Is that what is going on here? If so, is there any way to get the tileID to update as well as the tile image?

    Thanks in advance for your help!

    Tagged:

  • Everything looks ok to me, your code should work.

    Is Aimer sprite on the same layer as the tilemap? If it's on a layer with different parallax or scale rate, this can explain the issue. You may need to convert coordinates between layers.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • dop2000

    Thanks Dop!

    They are on separate layers but if that were an issue shouldn't the "set tile" action not work?

  • You are right..

    Can you show the full event for watering the dirt tile? (not just the dialog window)

  • dop2000

    No problem here it is:

    Its a little bit of a mess as I am in the middle of switching from spawning a tile image to actually modifying the tilemap as I think it will be lighter on the system.

    Essentially I can know if the call wass successful if the player watering animation is triggered and the only time it works is if I use TileID:0 and not TileID:1282

    Here is a link to the file if you want to take a look: drive.google.com/file/d/1W-16XIjrOijjUH7soWGSFGXsywrzp2LG/view

    Thanks!

  • You have two tilemaps, you are setting tile on DecorationsMap, but the same tile on Tilemap is still 0.

    I like the graphics, really nice!

  • dop2000

    OMG of course...can't believe I missed that.

    Thanks for taking the time to check it out Dop.

    And thanks for the compliment! I know you've probably seen a lot of games here on this forum so that means a lot coming from you.

  • No worries! I make mistakes like this all the time :)

    A word of advice - use constant variables instead of hard-coded tile numbers.

    For example: DIRT_TILE=1282

    The code will be easier to read, and if the tile number is changed in the future, you won't need to replace it in lots of events.

  • Really appreciate that dop2000

    Where/how would I set a constant variable like that?

    I'm a little new to all this...

  • Create a variable, set it as 'constant'. Use this variable instead of 1282 in events.

  • dop2000

    Perfect thank you so much!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)