Message Events via script

Announcements, support questions, and discussion for Quest Machine.
Post Reply
NicoMozes
Posts: 26
Joined: Sun Jun 05, 2022 4:18 am

Message Events via script

Post by NicoMozes »

Hi Tony,

Happy Wednesday! And happy 2025! I hope you are very well.

I have tried for a few months to figure this one myself, but no luck. I am trying to subscribe via script to the message system.

For example, I have a Quest Control component in a gameObject, and I'm using this:

questControl.SendToMessageSystem("Building:Selected");

But I cannot figure out how to receive this message. I'm trying to use Message Events, and I have looked at OnMessage, but I cannot understand how to use the MessageArgs via script. --> messageEvents.OnMessage(???);

Is there a way to do this via script? So far, I have used the Message Event component and just do everything via inspector, but the list of Messages to Listen for is quite long and I need to reduce it.

Thanks in advance!

Cheers
Nico
User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: Message Events via script

Post by Tony Li »

Hi and Happy New Year!

There's an example script in How To: Respond To Quest State Changes in Script

It listens for the message defined in the constant QuestMachineMessages.QuestStateChangedMessage, but you can listen for any message instead, like:

Code: Select all

MessageSystem.AddListener(this, "Building", "Selected");
Note: You could also send along a reference to the specific building that was selected, like:

Code: Select all

MessageSystem.SendMessage(this, "Building", "Selected", currentBuildingSelection);
and get that building reference from MessageArgs.firstValue.
NicoMozes
Posts: 26
Joined: Sun Jun 05, 2022 4:18 am

Re: Message Events via script

Post by NicoMozes »

Thanks Toni! That was exactly how to do it!

Cheers and keep up the amazing work you do!

Cheers,
Nico
User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: Message Events via script

Post by Tony Li »

Thanks, and glad to help!
Post Reply