Collision group sending message depending on object ID (SOLVED)

Hello~ it’s me again. I thougt I understand messaging and adressing now. Turns out I’m wrong appearently it only makes sense in my head. So sorry for another post :sweat:

My hero character is colliding with objects of the collision group „month“. Depending on the ID of the colliding Object I want the hero script to send a message to my gui.

Before I used for every month a own collision group and it worked fine (I know, I know not very efficent but it worked!). So I think the error must be in my hero script. I thought the identifier for the object to collide with was the „other_id“ and the ID it needs is the ID of the game object of the “months”.

Here the responsible part of my hero script

function on_message(self, message_id, message, sender)
(…)
elseif message_id == hash("collision_response") then
		if message.group == hash("month") then
			
		if other_id == hash("2feb") then
		msg.post("/level/blubb#messages", "feb")
		
	elseif other_id == hash("3mae") then
		msg.post("/level/blubb#messages", "mae")

	elseif other_id == hash("4ap") then
		msg.post("/level/blubb#messages", "ap")
(...)

For the record: I’m not getting any ERROR messages from my console
Thanks al lot for helping me out! :frog:

Have you tried printing “other_id”?

It’s message.other_id , not just other_id. :smile:

1 Like

No, but I never printed before and I think I’m doing it wrong… I’m not getting anything in my console… Not like this?

if other_id == hash("2feb") then
		msg.post("/level/blubb#messages", "feb")
		pprint(other_id)

Thanks! Sadly it’s still not working but thanks anyway :sweat_smile:

if other_id == hash("2feb") then
		msg.post("/level/blubb#messages", "feb")
		pprint(other_id)

if other_id is not hash(“2feb”) you will never see a print. Print it right at the top:

function on_message(self, message_id, message, sender)
(…)
elseif message_id == hash("collision_response") then
  print(message.other_id)

(EDIT: fixed typos.)

Okay thanks! The mistake has to be elsewhere… I’m only getting nil :face_with_raised_eyebrow:
Got to start searching again :sweat_smile:

Note that “other_id” is a field in the message table. So message.other_id.

Use the debugger, set a breakpoint right inside your elseif, run and hit the breakpoint, inspect, fix, win!

Okay, my now Looks like this:

elseif message.group == hash("month") then
		print(messsage.other_id)
		if message.other_id == hash("feb") then
			msg.post("/level/blubb#messages", "feb")

and I don’t know what changed over dinner but now I’m getting the ERROR notice

ERROR:SCRIPT: /hero/hero.script:138: attempt to index global 'messsage' (a nil value)
stack traceback:
	/hero/hero.script:138: in function </hero/hero.script:106>

And not a nil value anymore… weird

That’s at least one “s” to many… :slight_smile:

(that’s what you get for copy-pasting my typos!)

2 Likes

damn it!! :rofl: I’m busted and I trusted yout typos! Thanks!
Now it’s working and showing the correct hash over time

DEBUG:SCRIPT: hash: [/level/monate/2feb]
DEBUG:SCRIPT: hash: [/level/monate/3mae]
DEBUG:SCRIPT: hash: [/level/monate/4ap]
DEBUG:SCRIPT: hash: [/level/monate/5mai]
DEBUG:SCRIPT: hash: [/level/monate/6jun]
DEBUG:SCRIPT: hash: [/level/monate/7jul]
DEBUG:SCRIPT: hash: [/level/monate/8aug]
DEBUG:SCRIPT: hash: [/level/monate/9sep]
DEBUG:SCRIPT: hash: [/level/monate/10ok]
DEBUG:SCRIPT: hash: [/level/monate/11nov]
DEBUG:SCRIPT: hash: [/level/monate/12dez]

But still no Idea why it’s not working :thinking:

Good. This is the value you need to compare against:

if message.other_id == hash("/level/monate/2feb") then
  -- do something

already tried that… no change in the game…

Ok, have you tried the suggestion from @britzl ? Set a breakpoint at the first line in the function and stepping into it to see where the execution goes?

Found the mistake! I had in the other script a if and not a elseif :confounded:
It’s working! Thanks al lot :tada:

3 Likes