Referencing a database through Self Made Script
Posted: Tue Jun 20, 2023 1:34 pm
Hi there.
I'm trying to create a script that references a database so that I can use it special NPC interactions. The problem is I'm trying to get the conversation from that database, but I can never seem to find a suitable reference for that database. I've even tried adding the Extra Databases component to my Dialogue Manager, and made a coroutine to wait until the first frame of update to try and load those conversation, but it still seems to not be able to find the database.
Would you happen to know of a better way to reference this database to retrieve those conversations? Or maybe I'm going about it the wrong way?
Script for reference:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class RelationshipHandler : MonoBehaviour
{
public DialogueDatabase database;
[Header("Conversations")]
public List<string> ConversationNames;
List<Conversation> conversations;
public List<string> smallTalkNames;
List<Conversation> smallTalkConversations;
[Header("Relationship Stats")]
public int relationshipLevel;
void Start()
{
StartCoroutine(LoadConversations());
}
public void AddLevel()
{
//this happens at the end of the conversation to advance
relationshipLevel++;
}
public void CheckLevel()
{
//this would check the save data for that
}
private IEnumerator LoadConversations()
{
yield return new WaitForFixedUpdate();
for (int i = 0; i < ConversationNames.Count; i++)
{
conversations.Add(database.GetConversation(ConversationNames));
}
for (int i = 0; i < smallTalkNames.Count; i++)
{
smallTalkConversations.Add(database.GetConversation(smallTalkNames));
}
}
public void StartConversation()
{
DialogueManager.instance.StartConversation(ConversationNames[relationshipLevel], GameManager.instance.player.transform, this.gameObject.transform);
}
public void SmallTalkConversation()
{
DialogueManager.instance.StartConversation(ConversationNames[Random.Range(0, smallTalkConversations.Count)], GameManager.instance.player.transform, this.gameObject.transform);
}
}
I'm trying to create a script that references a database so that I can use it special NPC interactions. The problem is I'm trying to get the conversation from that database, but I can never seem to find a suitable reference for that database. I've even tried adding the Extra Databases component to my Dialogue Manager, and made a coroutine to wait until the first frame of update to try and load those conversation, but it still seems to not be able to find the database.
Would you happen to know of a better way to reference this database to retrieve those conversations? Or maybe I'm going about it the wrong way?
Script for reference:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using PixelCrushers.DialogueSystem;
public class RelationshipHandler : MonoBehaviour
{
public DialogueDatabase database;
[Header("Conversations")]
public List<string> ConversationNames;
List<Conversation> conversations;
public List<string> smallTalkNames;
List<Conversation> smallTalkConversations;
[Header("Relationship Stats")]
public int relationshipLevel;
void Start()
{
StartCoroutine(LoadConversations());
}
public void AddLevel()
{
//this happens at the end of the conversation to advance
relationshipLevel++;
}
public void CheckLevel()
{
//this would check the save data for that
}
private IEnumerator LoadConversations()
{
yield return new WaitForFixedUpdate();
for (int i = 0; i < ConversationNames.Count; i++)
{
conversations.Add(database.GetConversation(ConversationNames));
}
for (int i = 0; i < smallTalkNames.Count; i++)
{
smallTalkConversations.Add(database.GetConversation(smallTalkNames));
}
}
public void StartConversation()
{
DialogueManager.instance.StartConversation(ConversationNames[relationshipLevel], GameManager.instance.player.transform, this.gameObject.transform);
}
public void SmallTalkConversation()
{
DialogueManager.instance.StartConversation(ConversationNames[Random.Range(0, smallTalkConversations.Count)], GameManager.instance.player.transform, this.gameObject.transform);
}
}