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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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

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 :-) 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:

1
2
-- Build the tile physical
self:build()

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.

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

1
return self

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

1
2
3
4
5
6
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

Hmm strange, are you able to package up a simple demo showing off the issue and send it to me: support@justaddli.me

What is a gid?

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.

1
2
3
4
5
6
7
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
views:1962 update:2012/1/10 9:16:25
corona forums © 2003-2011