When I initiate my GameObject I loop through all if its dialogs. For each Dialog there is an action. Activate a quest or change NPC stage.
The method I pass to PopulateConversationList
below gets called when I click the final button in a dialog-interaction, i.e "Okay". Below I pass an ActiveNpcQuest(questId)
method, and pass the questId (get it from dialog data) like this:
//loop through all dialogs
for (int i = 0; i < dialogData.dialogs.Count; i++)
{
startsQ = dialogData.dialogs[i].dialogStartsQuest;
questId = dialogData.dialogs[i].dialogBelongToQuestId;
//if we have a quest, activate it (if already active, nothing happens)
if (startsQ)
{
PopulateConversationList(dialogData.dialogs[i].dialogsInThisStage[j].pages, "Okay", npcObject.npcName, dialogData.dialogs[i].npcStage, () =>
{
ActivateNPCQuest(questId); //This is the parameter I want to send
});
}
//If this dialog ALWAYS changes the NPC stage, then change stage
else if (autoChangeStage)
{
PopulateConversationList(dialogData.dialogs[i].dialogsInThisStage[j].pages, "Okay", npcObject.npcName, dialogData.dialogs[i].npcStage, ChangeNPCStage);
}
}
I guess the value of questId
doesnt actually get saved inside the ActivateNPCQuest
-method. Which makes a lot of sense. But Is there any way I can do what I want here?
My PopulateConversationList
declaration:
public void PopulateConversationList(List<string> fullConversation, string onLastPagePrompt, string npcName, int stage, UnityAction action)
My ActiveNpcQuest
-method:
public void ActivateNPCQuest(int id)
{
for (int i = 0; i < npcQuests.Count; i++)
{
if (npcQuests[i].questId == id && !npcQuests[i].active && !npcQuests[i].objective.isComplete)
{
npcQuests[i].active = true;
npcObject.hasActiveQuest = true;
}
}
}
Had real problems knowing what to search for, not sure if Unity Actions are Lambda expressions or events.