Problem with moving items between containers

Hi there, it's meggie! I'm making a packing game, and I have two containers, one called the playArea and one called tile. Tile is where the items are spawned and playArea is the box where the items are to be placed. The tile container sits above the playArea container, like a the head of a snowman made up of two boxes. I would like the player to be able to freely move the items between the two containers. playArea also snaps the items to the nearest 30px box inside. I have some code that seems to work for the x axis. -

    if (item.x < item.width/2 && item.x>-50){
        item.x = item.width/2
    } else if (item.x > bentoW-20-item.width/2 && item.x< bentoW+50){
        item.x = bentoW-20-item.width/2
    } else if (item.x <-50 && item.x > -240){
        item.addTo(tile)
        item.alp(1)
        zog("moving to tile a")
        return 
    } else if (item.x > bentoW+50) {
        item.addTo(tile)
        item.alp(1)
        zog("moving to tile b")
        return
    } else {
        item.loc(Math.round((item.x-item.width/2)/gridBlock)*gridBlock+item.width/2, Math.round((item.y-item.height/2)/gridBlock)*gridBlock+item.height/2, playArea)
        S.update()
    }

I tried to replicate it for the y-axis as follows

    if (item.y < item.height/2 && item.y > -40){
        item.y = item.height/2
    } else if (item.y > bentoH-20-item.height/2){
        item.y = bentoH-20-item.height/2
    } else if (item.y < -40){
        item.addTo(tile)
        zog("moving to tile c")
        item.alp(1)
        return
    } else {
        item.loc(Math.round((item.x-item.width/2)/gridBlock)*gridBlock+item.width/2, Math.round((item.y-item.height/2)/gridBlock)*gridBlock+item.height/2, playArea)
        S.update()
    }

I set the alpha so that when the item is in the playArea, it is 0.1 and when it is in the tile it is 1. What's happening is that when I try to move an item out of the box from the top of the box, for the first instance of it, the item will just drop where I pressup (which is what I want), but the rest of the time, the item will return to an alpha of 1, which seems to be indicating that it is in the tile container, but it will snap back to some location above the playArea.
Both of these blocks of code exist in the same pressup function for the playArea

I suspect that there might be a problem with the changing coordinates between the two tiles, but if that were the case, shouldn't the x part of the code not be working as well?

Are the x coordinates of the tile and the play the same? If they are, then that might be why the x is not broken. Will have a look tomorrow... just got in from a gallery opening and it is late.

It might be odd that the pressup is in the playArea. You might need separate pressup events. One for the tile - that one places it in the playArea. Then another for items already in the play area.

I also have a different pressup function for the tile - could it be that function that is messing with the way that the items drop between boxes? But it doesn't make sense that the first instance of me trying to move an item out of the playArea container from the top side of it would work then.

If you have a pressup in the tile then that is the pressup on the tile that will trigger - as you add the object to the other playArea in that pressup event. When you then pick it up when it is in the playArea then it is the pressup on the playArea that will trigger.

Are the two containers at the same x on the stage? That would explain why the x works and not the y as the y is quite different. You would normally use localToLocal() to handle the different coordinates. But maybe you can cheat....

const playArea = new Container(500,500).center();
const tile = new Tile(etc.).loc(playArea);
tile.loop(item=>{item.mov(0,-200)};

// This means they have the same coordinates when moving one into the other.

I think they are on the same X on the stage. I think what you said about the pressup for the different containers makes sense. Do I just need to switch the pressups for the containers then? Oh that's going to be confusing to try to fix. I like your idea to cheat, but I think the pressup for the tile would mess it up. I'll give it a try anyway! Thank you!