Comparing equal hashes returns false

Hi,

EDIT: when using hash_to_hex function, comparison works as I would expect, but I’m still confused why it doesn’t work directly?

I have issue when comparing equal hashes (according to console output, result is false)

This is my setup, I have a arena collection with arena game object, which handles combat system

Then I have actor collection which represents actor

In arena game object init function I create actors using actor_factory

function init(self)
	self.actors = {}
	
        -- other init code...
	local id = actor.create(math.ceil(self.tile_count/2))
	local id2 = actor.create(math.ceil(self.tile_count/2)+1, hash("simple_ai"))
	local id3 = actor.create(math.ceil(self.tile_count/2)+2, hash("simple_ai"))

	print("CREATE", hash("/collection1/actor") == id2) -- this return true as expected
	
	table.insert(self.actors, {
		id = id,
		ai = false,
		plan = false,
	})
	table.insert(self.actors, {
		id = id2,
		ai = true,
		plan = false,
	})
	table.insert(self.actors, {
		id = id3,
		ai = true,
		plan = false,
	})
	-- other init code...
end

actor.create function is following

local ACTOR_HASH = hash("/actor")
local ANIMATION_SPEED = 0.5

M.ANIMATION_SPEED = ANIMATION_SPEED

function M.create(index, ai)
	ai = ai or hash("")
	local p = a.get_tile_position(index)
	p.y = p.y + get_size_px(1) / 2

	local props = {}
	props[ACTOR_HASH] = { ai = ai }
	local ids = collectionfactory.create("#actor_factory", p, nil, props)
	local actor_id = ids[ACTOR_HASH]

	return actor_id
end

Later when I’m trying to delete actor from the arena I’m running this code

elseif message_id == a.MESSAGES.DELETE_ACTOR then
		print("REMOVE", message_id, message.id, hash("/collection1/actor"), hash("/collection1/actor") == message.id) -- this returns true
		for i=#self.actors,1,-1 do
			print(message.id, self.actors[i].id, hash("/collection1/actor") == self.actors[i].id, i) -- this return false, but hash_to_hex(hash("/collection1/actor") ) == hash_to_hex(self.actors[i].id) returns true
			if self.actors[i].id == message.id then
				--TODO debug this is not deleted
				table.remove(self.actors, i)
				pprint(self.actors)
			end
		end
end

This is relevant console output:

DEBUG:SCRIPT: CREATE	true <-- this is expected
DEBUG:SCRIPT: REMOVE	hash: [delete.actor]	hash: [/collection1/actor]	hash: [/collection1/actor]	true <-- this is expected
DEBUG:SCRIPT: hash: [/collection1/actor]	hash: [/collection2/actor]	false	3
DEBUG:SCRIPT: hash: [/collection1/actor]	hash: [/collection1/actor]	false	2 <-- this should be true, when using hash_to_hex it's true
DEBUG:SCRIPT: hash: [/collection1/actor]	hash: [/collection0/actor]	false	1

I assume that I’m doing something wrong, but I don’t know what. Would anyone be able to help? Thank you

This is curious.
Could you share a repro case project with us?
And what platform are you running on?

I think there is something wrong with our hash equality check tbh.
Looking at the code, it assumes some things that I’m not sure are true.

Please report an issue on github, and also a repro case project, and we’ll take a look!

1 Like

Hi,

I created new issue here Comparing game object ID hashes returns false, even if they are equal, i.e. printed value is same, and comparing with hash_to_hex returns true · Issue #9374 · defold/defold · GitHub with link to my project git and with my system information

If I can help further please let me know

Thank you

2 Likes