Best practices and questions about Actor data

Announcements, support questions, and discussion for the Dialogue System.
Ejbkt
Posts: 2
Joined: Sat May 30, 2020 8:07 am

Best practices and questions about Actor data

Post by Ejbkt »

I just acquired this asset, it sounds fantastic! I'm just having trouble integrating it into my game, and I'd like to ask for advice.

My game is a management-style game where you're a teacher with a class of students. Depending on their traits and your dialogue choices they'll perform differently in the classroom and have different dialogue "stories".

I was using ScriptableObjects to store character data for the students. Now I have this asset, I realize it may be easier to store their data in the Dialogue database instead, but I have a few questions:

1) Is it sensible to put all my character data in the Dialogue database?
2) How do I get a list of the Actors in C# code to use in a scene?
3) How would I sync a variable in my scene (say a "Student engagement level") with an Actor number field? So that if one changes, the other changes too.
4) Is it possible to put ScriptableObjects in a custom Actor field?

Thanks heaps!
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Best practices and questions about Actor data

Post by Tony Li »

Thanks for using the Dialogue System!
Ejbkt wrote: Sat May 30, 2020 8:23 am1) Is it sensible to put all my character data in the Dialogue database?
Sure. You can define custom actor fields in the Dialogue Editor's Templates section. In the Actors section, create an actor for each character and set the actor's field values. An advantage of doing this is that Dialogue System data, such as these field values, are included in saved game data, so you don't have to do anything extra to save them.
Ejbkt wrote: Sat May 30, 2020 8:23 am2) How do I get a list of the Actors in C# code to use in a scene?
Use DialogueManager.masterDatabase:

Code: Select all

foreach (Actor actor in DialogueManager.masterDatabase.actors)
{    
    Debug.Log("Actor " + actor.Name + " is " + actor.LookupInt("Age") + " years old.");
}
Ejbkt wrote: Sat May 30, 2020 8:23 am3) How would I sync a variable in my scene (say a "Student engagement level") with an Actor number field? So that if one changes, the other changes too.
If you maintain the value in an Actor number field, then in your script you can use a property instead of a variable. Use DialogueLua.GetActorField() and GetActorField() to access the value:

Code: Select all

public class Student : MonoBehaviour
{
    [Actor] public string actor; //<--(Can choose actor in inspector dropdown.)
    
    public int EngagementLevel
    {
        get { return DialogueLua.GetActorField(actor, "Student engagement level").asInt; }
        set { return DialogueLua.SetActorField(actor, "Student engagement level", value); }
    }
}
That's just one way of approaching it. Alternatively, if you want to keep the value in your script instead of the dialogue database, you can write C# methods to get and set the value. Then register those methods with the Dialogue System so conversations' Conditions and Script fields can use them.
Ejbkt wrote: Sat May 30, 2020 8:23 am4) Is it possible to put ScriptableObjects in a custom Actor field?
No. To support full export/import with external editors such as Chat Mapper, articy:draft, and Twine, dialogue databases don't contain any Unity-specific asset types, with the exception of actors pointing to portrait images. (Those are handled specially.)

However, in the upcoming version 2.2.7, each dialogue entry node can have a UnityEvent to which you can assign scene objects. So dialogue entry nodes can work with scripts in a scene.
Ejbkt
Posts: 2
Joined: Sat May 30, 2020 8:07 am

Re: Best practices and questions about Actor data

Post by Ejbkt »

Thank you very much, that is a huge help! =)
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Best practices and questions about Actor data

Post by Tony Li »

Happy to help! :)
s0963123
Posts: 7
Joined: Mon Jun 29, 2020 1:10 am

Re: Best practices and questions about Actor data

Post by s0963123 »

I have similar question too.

I have added a custom field [location] for all my actors.
I want to go through all the actors to find which one has/is in certain location.

I have playmaker too, if I only have one actor, I could simply use: Get Lua Field.
But since there would be over 100 actors, what is the best way to do it?
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Best practices and questions about Actor data

Post by Tony Li »

Hi,

In a C# script, you could do this:

Code: Select all

foreach (var actor in DialogueManager.masterDatabase.actors)
{
    if (DialogueLua.GetActorField(actor.Name, "location").asString == "Certain Location")
    {
        Debug.Log(actor.Name + " is in Certain Location");
    }
}
Here's a new PlayMaker action that gets an array of all actor names (or all quest names, or all variable names, etc.):

DS_PlayMakerSupport_2020-06-30.unitypackage
(EDIT: Replaced with full integration package.)

Once you have the array, you can loop through it in PlayMaker and use the GetLuaField action to find the actor(s) in the certain location.

This action will also be in the updated PlayMaker Support package in DS version 2.2.8.
s0963123
Posts: 7
Joined: Mon Jun 29, 2020 1:10 am

Re: Best practices and questions about Actor data

Post by s0963123 »

Tony Li wrote: Tue Jun 30, 2020 9:10 am Here's a new PlayMaker action that gets an array of all actor names (or all quest names, or all variable names, etc.):
Nice to hear that. I think it would be of great help. Any plan on when to release DS version 2.2.8 ?

I import the package to try out but it return this error message:

Assets\Pixel Crushers\Dialogue System\Third Party Support\PlayMaker Support\Actions\GetAllLuaElements.cs(14,10): error CS0246: The type or namespace name 'LuaElementTypeEnum' could not be found (are you missing a using directive or an assembly reference?)

Any quick fix for that? If not, I could just wait for 2.2.8.
Thanks again.
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Best practices and questions about Actor data

Post by Tony Li »

Oops, I tried to minimize the file size by selectively exporting files, and I missed one. Here's the entire PlayMaker Support package, which isn't big either:

DS_PlayMakerSupport_2020-06-30.unitypackage

DS 2.2.8 should be out in mid-July.
s0963123
Posts: 7
Joined: Mon Jun 29, 2020 1:10 am

Re: Best practices and questions about Actor data

Post by s0963123 »

new error :

Assets\Pixel Crushers\Dialogue System\Third Party Support\PlayMaker Support\Actions\GetAllLuaElements.cs(65,117): error CS0117: 'QuestState' does not contain a definition for 'Grantable'
User avatar
Tony Li
Posts: 22054
Joined: Thu Jul 18, 2013 1:27 pm

Re: Best practices and questions about Actor data

Post by Tony Li »

Hi,

Can you update to a newer version of the Dialogue System? The "Grantable" quest state was added a few versions back.
Post Reply