[SOLVED] Is there any way to get a component url through code?

hello I have a small problem, I’m trying to make my player character have knockback with one collision component (named hitbox) and I want to use a different collision component for the sword on the same player character, I am trying to make sure my code can tell if a contact point response is coming from the hitbox and the soon to be implemented hurtbox. After doing some research I found that sender is the full url of whatever is sending the message.

so how do I get the full url of my hitbox component through code?

right now I have this code

function on_message(self, message_id, message, sender) 
if message_id == hash("contact_point_response") then 
	local normal = message.normal
	if self.knockback_state == false then
		self.health = self.health - 1
		print(self.health)
	end 
	self.knockback_dir = normal
	self.knockback_state = true
	timer.delay(self.knockback_time, false, end_knockback)
	msg.post(".", "release_input_focus")
	
	print(sender)
end
end 

image

I know that I need to modify my code so that I can compare the sender with my hitbox component but doing this does not work since I need a full url

function on_message(self, message_id, message, sender)
	
	if message_id == hash("contact_point_response") and sender == hash("#hitbox") then 
		local normal = message.normal
		if self.knockback_state == false then
			self.health = self.health - 1
			print(self.health)
		end 
		self.knockback_dir = normal
		self.knockback_state = true
		timer.delay(self.knockback_time, false, end_knockback)
		msg.post(".", "release_input_focus")
		
		print(sender)
	end
end

Please let me know if there is a way to get a url through code or if there is an easier way to have two collision boxes on a game object

Thanks

You can get the collision object component with sender.fragment. And # is not part of the component name.

if sender.fragment == hash("hitbox") then
2 Likes

Thank you it worked,

I’ll mark it as an answer once I figure out how to do that.