Page 2 of 2
Re: How to manipulate tasks in one quest
Posted: Sat Aug 17, 2024 8:02 am
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.
Re: How to manipulate tasks in one quest
Posted: Sat Aug 17, 2024 8:38 am
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.
Re: How to manipulate tasks in one quest
Posted: Mon Aug 19, 2024 1:52 am
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.
Re: How to manipulate tasks in one quest
Posted: Mon Aug 19, 2024 8:31 am
by Tony Li
Hi,
Sorry, I thought the example scene answered that. The "Power Off Button" and "Power On Button" use SendToMessageSystem:
- sendToMessageSystem.png (59.84 KiB) Viewed 942 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?
Re: How to manipulate tasks in one quest
Posted: Mon Aug 26, 2024 6:48 am
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.
Re: How to manipulate tasks in one quest
Posted: Mon Aug 26, 2024 5:28 pm
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").