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

afterEnter event not triggering for zone #2936

Open
1 of 5 tasks
KaQn opened this issue Oct 3, 2024 · 2 comments
Open
1 of 5 tasks

afterEnter event not triggering for zone #2936

KaQn opened this issue Oct 3, 2024 · 2 comments
Labels
Priority: Medium This issue may be impactful and needs some attention. Status: Pending Test This PR or Issue requires more testing Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.

Comments

@KaQn
Copy link

KaQn commented Oct 3, 2024

Priority

Medium

Area

  • Datapack
  • Source
  • Map
  • Other

What happened?

Issue: afterEnter event not triggering in custom zone

I encountered an issue while setting up a custom zone for my server. I wanted to apply a condition to the player upon entering a specific area, but I noticed that the afterEnter event wasn’t being triggered, despite the setup being correct.

Upon investigating, I found that removing the true from the following line made the afterEnter event work as expected:

local afterEnter = EventCallback("ZoneEventAfterEnter", true)

You can easily testthis by adding a print statement in the following code:

function afterEnter.zoneAfterCreatureEnter(zone, creature)
print("After enter executes")
if zone ~= self.zone then
return true
end
self.afterEnter(zone, creature)
end

This suggests there might be an issue with the skipDuplicationCheck boolean.

Removing the true causes a series of other problems in the console:

image

What OS are you seeing the problem on?

Windows

Code of Conduct

  • I agree to follow this project's Code of Conduct
@KaQn KaQn added the Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors. label Oct 3, 2024
@github-actions github-actions bot added Priority: Medium This issue may be impactful and needs some attention. Status: Pending Test This PR or Issue requires more testing labels Oct 3, 2024
@KaQn
Copy link
Author

KaQn commented Oct 16, 2024

I modified ZoneEvent to add a print to check things out and it printed the stuff in the image, it looks like self.zone is always hazard.gnomprona-gardens, I tried going to gnomprona gardens and hazard seems to be the only working afterEnter event.

if self.afterEnter then
	local afterEnter = EventCallback("ZoneEventAfterEnter", true)
	function afterEnter.zoneAfterCreatureEnter(zone, creature)
		print(zone:getName())
		print(self.zone:getName())
		if zone ~= self.zone then
			return true
		end
		self.afterEnter(zone, creature)
	end

	afterEnter:register()
end

image

@mdbeng
Copy link

mdbeng commented Oct 16, 2024

The error likely stems from the fact that you r trying to create a second instance of the afterEnter variable and assign it a new event callback, which could be causing a conflict with another EventCallback object already in place. To avoid it, you can refactor the code to check if self.afterEnter is already assigned or modify the logic to avoid re-registering the same event callback multiple times.

Note: in the console tells you exactly what it is

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: Medium This issue may be impactful and needs some attention. Status: Pending Test This PR or Issue requires more testing Type: Bug Inconsistencies or issues which will cause an issue or problem for users or implementors.
Projects
None yet
Development

No branches or pull requests

2 participants