pulp-to-lua icon indicating copy to clipboard operation
pulp-to-lua copied to clipboard

Race condition when calling "goto" from within a "wait"

Open kounch opened this issue 3 years ago • 2 comments

I have a pulpscript recursive call (to make some tiles slippery), like this:

on pSlip do
	x = event.px
	y = event.py
	mSr = type x,y
	if mSr=="item" then
		x += event.dx
		y += event.dy
		ignore
		wait 0.1 then
			mSr = type x,y
			if mSr!="item" then
				mSr = name x,y
				if mSr=="floor" then
					mSr = "item"
				end
			end
			listen
			if mSr=="item" then
				remaining++
				goto x,y
				call "pSlip"
			end
		end
	end
end

After being processed with pulp-to-lula, it doesn't work correctly. The player tile moves through the slippery tiles, but its x,y coordinates are then reset to first tile.

After looking and debugging with the simulator, it looks like it can be possible that something about the wait call may cause to change player.x and player.y coordinates, between the call to smoothMovementBegin and smoothMovementEnd, when PTLE_SMOOTH_MOVEMENT_SPEED is 0.

I have found a possible solution changing the code of smoothMovementEnd from

local function smoothMovementEnd()
    local player = pulp.player
    player.x = pulp.smooth_true_x
    player.y = pulp.smooth_true_y
    pulp.PTLE_SMOOTH_OFFSET_X = 0
    pulp.PTLE_SMOOTH_OFFSET_Y = 0
end

to

local function smoothMovementEnd()
    local player = pulp.player
    if pulp.PTLE_SMOOTH_MOVEMENT_SPEED > 0 then
        player.x = pulp.smooth_true_x
        player.y = pulp.smooth_true_y
    end
    pulp.PTLE_SMOOTH_OFFSET_X = 0
    pulp.PTLE_SMOOTH_OFFSET_Y = 0
end

but i'm not totally sure that it's a good solution (i'm a newbie to lua language).

kounch avatar Nov 15 '22 18:11 kounch

I assume pSlip is being called from update?

Do you have a .json file I can try on my end? You can DM me on Discord (NaOH#1432)

nstbayless avatar Nov 20 '22 23:11 nstbayless

DM sent on Discord.

kounch avatar Nov 21 '22 06:11 kounch