Cant set tile gid

Happy New Year!

I have this code that changes the gid of a tile whenever you drag a tile. I dont know why it’s not working. It acts as if I have destroyed the tile instead of setting a new gid. First I thought this was because maybe I was trying to set a non-existent or non-valid gid. But as far as I know this isn’t true, because it’s set automatically with the correct gid(i.e 352 for grass).

Here’s the code:

local startGridPos = nil  
local notBuildableGid = nil  
local dragging = false  
local lastTile = nil  
local lastRow = 1; local lastCol = 1  
  
local onTouch = function( event )  
 if not startGridPos then  
 startGridPos = \_functions.screenToGridPosition(event)  
 end  
  
 --I have also set an onTap event listener, so I need to know only when it's dragging  
 if event.phase == "moved" then  
  
 local currTile = \_functions.getTileFromScreen( event )  
  
 --Set the gid ONLY for the first time  
 if not dragging then  
 if not notBuildableGid then  
 notBuildableGid = currTile.gid  
 end  
 end  
  
 dragging = true  
  
 currTile.alpha = 0.5  
 currTile:setImage(notBuildableGid)  
 currTile:getVisual():toFront()  
 --currTile:destroy()  
 local row, col = currTile:getGridPosition()  
  
 if not lastTile then  
 lastTile = currTile  
 end  
  
 lastRow = row;  
 lastCol = col;  
 end  
  
 if event.phase == "ended" then  
 if dragging then  
  
 dragging = false  
 notBuildableGid = nil  
 startGridPos = nil  
 lastTile = nil  
 lastRow = 1  
 lastCol = 1  
  
 local currTile = \_functions.getTileFromScreen( event )  
  
 if \_functions.\_isObstacle( \_functions.screenToGridPosition(event) ) then  
 print("Is Obstacle")  
 end  
 end  
 end  
end  

It doesnt give me any errors. It just doesn’t set the tile to any image(whatever gid I put in there). Btw, the tileset Im using it’s the forest.png from Lime’s Tutorials Number 13(“Moving a map via touch”), really good tutorials- I recommend them-.
I would appreciate any help anyone could give me. Thank you! [import]uid: 109816 topic_id: 19905 reply_id: 319905[/import]

Hey, this is a bug in the current version of Lime that is fixed in the upcoming version ( which I promise really is coming out soon :slight_smile: MonkeyDead is sort of going through a transitional period right now which is slowing things down ) but it is an easy fix, just go into “lime-tile.lua” and find the Tile:setImage() function.

Towards the bottom you should find this code:

-- Build the tile physical  
self:build()  

Just put this after it:

-- Bring the new tile into focus  
self:getVisual():toFront()  
self:getVisual().isVisible = true  

Hope that fixes it! [import]uid: 5833 topic_id: 19905 reply_id: 77392[/import]

Thank you very much, it does fix it.

It sets the tile image, but right now Im having a new problem, the gid returned by currTile.gid appears to be incorrect(it returns 352 which is the grass tile, when I touch the tree tile). Do you have any idea why this might be?(It’s the same code as before).

Thank you very much Graham. [import]uid: 109816 topic_id: 19905 reply_id: 77400[/import]

Ok just put in a fix for this, what you need to do is after those lines you just added also add this:

return self  

Then in your code where you have this:

currTile:setImage(notBuildableGid)  

Replace it with this:

currTile = currTile:setImage(notBuildableGid)  

I know that’s a bit of a weird usage, but until I can think of a better way to structure that setImage function it should do :slight_smile: [import]uid: 5833 topic_id: 19905 reply_id: 77404[/import]

It’s still not working. Btw, the notBuildableGid which I set the image with currTile:setImage(notBui…) it’s set before in this:

if not dragging then  
 if not notBuildableGid then  
 --It returns the wrong gid in here(before doing the currTile = currtile...  
 notBuildableGid = currTile.gid  
 end  
 end  

and then it’s:

[code]

currTile = currTile:setImage…

[/code] [import]uid: 109816 topic_id: 19905 reply_id: 77406[/import]

Hmm strange, are you able to package up a simple demo showing off the issue and send it to me: support@justaddli.me [import]uid: 5833 topic_id: 19905 reply_id: 77410[/import]

What is a gid? [import]uid: 24111 topic_id: 19905 reply_id: 77411[/import]

I think it stands for Global ID. It’s the id according to the tileset tile position.

From a previous post of mine that Graham answered.

[code]
The GID is controlled by your Tilesets in Tiled.

Essentially each individual tile in a tileset has an ID, these start from 1 and then go sequentially up from left to right, top to bottom. With me so far?

Then the GID ( global id ) is the tiles’ ID but each tilesets first id is 1 more than the last id of the previous tileset.

http://dl.dropbox.com/u/571145/globalIDs.png
[/code] [import]uid: 109816 topic_id: 19905 reply_id: 77413[/import]