Objects appearing in wrong room using "wait" - Web Player Bug or bad code?

Seem to be getting either an Web Player bug or a code bug, can’t be sure which, with objects appearing in the wrong room when a “wait” is triggered after moving rooms.

On the left is where these objects should be (in the field, bottom left), and where they will never move from.
On the right is where they’re appearing (so same place, bottom left, but wrong room).

it’s just simple swap code:

on collect do
	
	Field1--
	money += 2
	swap "BlankTileSwap"
	
	wait 30 then
		swap "Field1Furrow"
	end
	
end
	

So when it’s swapping back to “Field1Furrow” they’re swapping/displaying in whatever room I happen to be in rather than their original location.

As to whether this is a bug or bad code, I couldn’t say. BUT, I did find a method that is able to do what you want, albeit messy. First, check if the player is in the same room as the item (Field1Furrow in your case). Inside the on collect do event, event.room will always be whatever it was when it was called, even if the player changes rooms during that wait timer. So, in the player script:

on enter do
	currentRoom = event.room
end

Now we can compare currentRoom with event.room. What I had hoped would work is:

on collect do
	
	Field1--
	money += 2
	swap "BlankTileSwap"
	
	wait 30 then
        while currentRoom!=event.room do
             wait 0.1 then // doesn't work :(
             end
        end
		swap "Field1Furrow"
	end
	
end

Unfortunately, it looks like pulp pays no mind to wait functions inside of while loops, and the console immediately throws an error after the while loop goes through 400 times which I guess is just a safety against infinite loops. So with no loops, and no iterators, this is what I got:
First, in the game script:

on load do
     queue_1_room = 999 //dummy value
     queue_2_room = 999
     // and so on for as big of a queue you want
end

on enter do
	call "drawItems"
end

on drawItems do
	log "Drawing all queued items for {event.room}..."
	if queue_1_room==event.room then
		tell queue_1_x,queue_1_y to
			swap queue_1_tile
		end
		queue_1_room = 999
    elseif queue_2_room==event.room then
        tell queue_2_x,queue_2_y to
            swap queue_2_tile
        end
        queue_2_room = 999
        // and so on for as big as you want your queue...	
    end
end

Then, in Field1Furrow script:

on collect do
	
	Field1--
	money += 2
	swap "BlankTileSwap"
	
	wait 30 then
        if currentRoom!=event.room then
            swap "Field1Furrow"
        else
			if queue_1_room==999 then
				queue_1_room = event.room
				queue_1_x = event.x
				queue_1_y = event.y
				queue_1_tile = event.tile
			elseif queue_2_room==999 then
				queue_2_room = event.room
				queue_2_x = event.x
				queue_2_y = event.y
				queue_2_tile = event.tile
            end
            // and so on....
	    end
	
end

If anyone was any more elegant ways to do this I’d love to see! One thing to note is that while “drawItems” can be its own function, the if tree in Field1Furrow cannot, because event.room will be different then. Also, maybe the devs can add waits inside while loops as a potential feature to simplify this down a ton : )

I found what I think is the same bug: Bug in swap with wait

My solution is to check which room the player is in before the wait, and if the room has changed, don’t execute the swap.

To set this up, I keep a global player_room variable up to date using the Player object’s on enter event to set it: player_room = event.room

The downside to this is that the wait loop was meant to eventually restore the tile to its original state, and this prevents that, so the tile needs to be reset some other way; I used on enter on the temporary sprite tile to swap it back to the original.

I hope this bug can be fixed soon, but I’m having fun with Pulp!