How to manipulate tasks in one quest

Announcements, support questions, and discussion for Quest Machine.
Daffy
Posts: 19
Joined: Wed Feb 06, 2019 1:17 pm

Re: How to manipulate tasks in one quest

Post by Daffy »

In your example is a bug.
If I will set the power off before start the project it will only show gray tasks with clothes BUT the button is interactable and you can collect clothes even the power is off.
User avatar
Tony Li
Posts: 22083
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to manipulate tasks in one quest

Post by Tony Li »

Hi,

That's irrelevant to Quest Machine. You could add this line to Power.cs if you want to handle that case:

Code: Select all

void Start() { getClothesButton.interactable = isPowerOn; }
For simplicity, I didn't bother doing that since your own implementation will be different.
Daffy
Posts: 19
Joined: Wed Feb 06, 2019 1:17 pm

Re: How to manipulate tasks in one quest

Post by Daffy »

Ok, but could you please answer me this one question, because I'm asking third time and still got 0 answers from you.
Daffy wrote: Sat Aug 17, 2024 7:55 am Ok thanks, I checked and I understand this way, but I still want to know why SendTomeesageSystem() method doesn't work in method OnMessage(MessageArgs messageArgs). Could you please tell me why this doesn't work.
Because it is like this, or maybe there is something wrong.

I even put SendTomeesageSystem() method in your script Power.cs (also in OnMessage method) you provide to me, and still, quest don't receive this Messages.
User avatar
Tony Li
Posts: 22083
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to manipulate tasks in one quest

Post by Tony Li »

Hi,

Sorry, I thought the example scene answered that. The "Power Off Button" and "Power On Button" use SendToMessageSystem:

sendToMessageSystem.png
sendToMessageSystem.png (59.84 KiB) Viewed 897 times

The scene wouldn't work if this weren't working. The buttons use SendToMessageSystem to send "Power"+"Off" and "Power"+"On". The Power and CheckPowerQuestCondition scripts both listen for these messages.

What specific question do you have about SendToMessageSystem?
Daffy
Posts: 19
Joined: Wed Feb 06, 2019 1:17 pm

Re: How to manipulate tasks in one quest

Post by Daffy »

I was talking about my code.

Here it is from the previous post:

Code: Select all

public bool ElectroStateSwitch
{
    get => _electroState;
    set => _electroState = value;
    
}
[SerializeField] private bool _electroState;
[SerializeField] private string _messageElectroOn; //Q1:E1
[SerializeField] private string _messageElectroOff; //Q:E

private void Start()
{
    MessageSystem.AddListener(this, "Is", "Electro"); // subscribe for a message sending from quest node "Is Electro?"
}
private void Awake()
{
    foreach(var socket in _electroSockets)
    {
        socket.ElectroFuseBox = this;
    }

}
public void TurnOffElectro()
{
    ElectroStateSwitch = false;
    SendToMessageSystem(_messageElectroOff);
}

public void SendInformationAboutElectro()
{
    ElectroStateSwitch = !ElectroStateSwitch;
    SendToMessageSystem(ElectroStateSwitch? _messageElectroOn : _messageElectroOff); //this one works perfeclty fine. If the player will turn on/off electricity by fusebox then all nodes are responding to this
}

public void OnMessage(MessageArgs messageArgs)
{
    Debug.Log(messageArgs.sender + messageArgs.message + messageArgs.parameter); // It is debuging correctly, is sender and Is Electro   
    SendToMessageSystem(ElectroStateSwitch ? _messageElectroOn : _messageElectroOff); //in debug log is ok, but the nodes doesnt bother about it
}
The method SendToMessageSystem in method OnMessage doesn't work. I can see debugs but the quest node don't change (yes, he is listening to the specific message).

I'm trying to make this working:
quest node sending a message to a script - it works
the script receive the message from quest node - it works
make some logic inside using OnMessage method - it works
sending back the message to the quest node using SendToMessageSystem() insinde the method OnMessage - doesn't work.

My question from the beginning is why method SendToMessageSystem() doesnt work when its called inside OnMessage . The exactly same method works in a different place in code. I have a good message and parameters.
User avatar
Tony Li
Posts: 22083
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to manipulate tasks in one quest

Post by Tony Li »

Hi,

What is SendToMessageSystem?

Here's an updated example:

QM_DaffyExample_2024-08-26.unitypackage

I updated the Power.cs script's OnMessage() to send a message using MessageSystem.SendMessage:

Code: Select all

        public void OnMessage(MessageArgs messageArgs)
        {
            isPowerOn = string.Equals(messageArgs.parameter, "on", System.StringComparison.OrdinalIgnoreCase);
            QuestMachine.defaultQuestAlertUI.ShowAlert($"Power: {isPowerOn.ToString().ToUpper()}");
            getClothesButton.interactable = isPowerOn;

            MessageSystem.SendMessage(this, isPowerOn ? _messageElectroOn : _messageElectroOff, string.Empty);

        }
In the inspector I set _messageElectroOn to "Electro On" and _messageElectroOff to "Electro Off".

In the quest, I changed the "Lost Power?" node to listen for the message "Electro Off".

This works.

Maybe you're sending the wrong message? Note that the QuestControl component's SendToMessageSystem() method takes a single string such as "Get:Carrot" and sends the message="Get" and parameter="Carrot" to the MessageSystem.

However, MessageSystem.SendMessage() uses separate message and parameter values: MessageSystem.SendMessage(this, "Get", "Carrot").
Post Reply