Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kounch opened this issue Nov 15, 2022 · 2 comments
Open

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

kounch opened this issue Nov 15, 2022 · 2 comments

Comments

@kounch
Copy link

kounch commented Nov 15, 2022

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 kounch changed the title Race condition when calling from within a "wait" Race condition when calling "goto" from within a "wait" Nov 15, 2022
@nstbayless
Copy link
Owner

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)

@kounch
Copy link
Author

kounch commented Nov 21, 2022

DM sent on Discord.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants