Using and resetting conversation fields to track "times visited"

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
wedgiebee
Posts: 16
Joined: Wed May 25, 2022 6:40 pm

Using and resetting conversation fields to track "times visited"

Post by wedgiebee »

Hello, I have a conversation where I want to track the number of times that particular conversation has been visited, and branch into different dialogue accordingly.

I've added a field called "TimesVisited" to that conversation's fields. I'm using fields instead of a global variable because I don't want it to be included in save data.

The context is it's a conversation that happens repeatedly during a boss fight. So if the player dies, and the scene reloads, I want that value (and any other conversation fields I add) to reset to their default value, but I'm not sure how to do that.

I tried making a script that would reset all conversation's fields to their default value, by copying the code to reset variables to their initial value from this post (https://www.pixelcrushers.com/phpbb/vie ... a36#p39138). But conversation fields don't seem to have a "initial value" available.

Is there another way to iterate through all conversations and reset all their custom fields when a scene loads?
User avatar
Tony Li
Posts: 21678
Joined: Thu Jul 18, 2013 1:27 pm

Re: Using and resetting conversation fields to track "times visited"

Post by Tony Li »

Hi,

When the player dies, are you loading a saved game (e.g., from a checkpoint)? If so, then it should just work the way you describe; no need to do anything else.

If you reload the scene without loading a saved game, you can add a script that resets conversations' "TimesVisited" fields. Something like:

Code: Select all

public void Die()
{
    // Set all conversations' TimedVisited fields to zero:
    foreach (var conversation in DialogueManager.masterDatabase.conversations)
    {
        DialogueLua.SetConversationField(conversation.id, "TimesVisited", 0);
    }
    // Reload the current scene:
    SaveSystem.LoadScene(SceneManager.GetActiveScene().name);
}
Post Reply