Clicking on an object to alter a quest state

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
pjj5049
Posts: 3
Joined: Tue Mar 03, 2015 2:31 pm

Clicking on an object to alter a quest state

Post by pjj5049 »

I am currently working on a click based game, where the player will select an item, and then based on whether it is the correct item or not, a quest state will be updated. I created a script that makes use of the onMouseDown function to send a message when the item is clicked, but I'm not quite sure how I would be able to make the quest state updated. Any advice would be appreciated. Thank you!
User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Clicking on an object to alter a quest state

Post by Tony Li »

Hi,



You can use the QuestLog class:

using PixelCrushers.DialogueSystem;



QuestLog.SetQuestState("My Quest", QuestState.Success);
pjj5049
Posts: 3
Joined: Tue Mar 03, 2015 2:31 pm

Clicking on an object to alter a quest state

Post by pjj5049 »

Hey Tony,



So that works perfectly! I see in the info console that the quest state is updated. I'm having an issue similar to a similar poster now, I believe. I couldn't quite get the solution posted working.



What I want to do is this:



1. Quest state becomes active during conversation - done



2. Sequence is triggered during the conversation to show an assortment of objects, and NPC will have an animation to point to one which is correct. When the user clicks the right item, quest state is updated to success, when wrong item is pressed, quest state remains active. The camera must be fixed here, so I've had this just occur in a sequence. This would be an NPC node in the dialog list



3. When any object is pressed, continue with the conversation with an NPC response stating whether the object pressed was correct or not. This is where I'm having the issue. I am not able to get the conversation to continue, with the NPC's old response still listed (ex: "pick this item"). I have a condition set to only do the next responses if the quest state is active or success, but I can't quite get them to start. 







Any help, documentation or ideas of how to proceed is appreciated.


User avatar
Tony Li
Posts: 22093
Joined: Thu Jul 18, 2013 1:27 pm

Clicking on an object to alter a quest state

Post by Tony Li »

Hi,



This is a great place to use the "@Message" sequence command syntax. This syntax tells a sequencer command to wait until it receives a specified message.



For example, let's say the player is Indiana Jones. The Grail Knight has just asked him to choose which cup is the Holy Grail. At this point in the game, you want to show the cups and wait for the player to click one.



For convenience, let's say all three cups are child GameObjects of a GameObject named "Table" which starts inactive (hidden). Each cup has a script that implements OnMouseDown() to handle mouse clicks.



The dialogue entry would look something like this:



Dialogue Text: "Choose wisely..."



Sequence:

SetActive(Table);

Camera(Closeup, Table);

None()@Message(ChoseCup)

The first two sequencer commands show the table in a closeup shot.



The third sequencer command waits until the sequencer receives the message "ChoseCup". Then it does nothing. The only purpose of this command is to wait for the message. You could play an audio clip instead:

SetActive(Table);

Camera(Closeup, Table);

Audio(trumpet)@Message(ChoseCup)

The sequence above assumes an audio clip named "trumpet" is in a Resources folder.







The cup script's OnMouseDown() method should call Sequencer.Message("ChoseCup"):

using UnityEngine;

using PixelCrushers.DialogueSystem;



public class Cup : MonoBehaviour {



public bool isHolyGrail;



void OnMouseDown() {

DialogueLua.SetVariable("ChoseWisely", isHolyGrail);

Sequencer.Message("ChoseCup");

}

}

The script above also sets a Dialogue System variable, "ChoseWisely".







The next dialogue entries can have conditions that check the value of Variable[ChoseWisely]. For example:



Conditions: Variable[ChoseWisely] == true



Dialogue Text: "You chose... wisely."



Script: Quest[Find_the_Holy_Grail].State = "success"






Post Reply