Page 1 of 1

Unable to get actor field.

Posted: Thu Sep 17, 2020 8:21 pm
by MOTYSHIZ
Hello there.

I seem to be having issues getting an actor field in my C# script via DialogueLua.GetActorField.
This is strange for me, because I am able to get another field from the same actor in the same area of script.

In this script, I attempt to get an actor's "Attack" power.
Screenshot 2020-09-17 172023.png
Screenshot 2020-09-17 172023.png (117.4 KiB) Viewed 277 times
As you can see by the middle Debug.Logs, I read out the actor's name, "Health" field, and their "damageAmount" which is actually their "Attack" field.
The console output is shown below.
Screenshot 2020-09-17 171537.png
Screenshot 2020-09-17 171537.png (22.41 KiB) Viewed 277 times
This is what the actor's fields looks like. You can verify that the proper name is used because not only is the name printed out in the above log, but their health field was properly printed out.
These values were set in-editor prior to runtime:
Screenshot 2020-09-17 171753.png
Screenshot 2020-09-17 171753.png (26.15 KiB) Viewed 277 times
Please let me know if there is anything I am missing.
Thank you very much!

Justin

Re: Unable to get actor field.

Posted: Thu Sep 17, 2020 8:31 pm
by MOTYSHIZ
I believe I have a lead, and that I forgot to mention that I am using 3 separate databases in my turn-based battle system (that uses the dialogue system).

The Health field was appearing properly because I had called DialogueLua.SetActorField(); on it somewhere else in code for testing. When I remove the DialogueLua.SetActorField() for the Health field, it no longer reads properly.

I am guessing that this is because the database that DialogueLua.GetActorField() refers to is the "initial database" set in the current scene's DialogueSystemController. I did think this was the case because I was previously receiving the actor's health property before.

How might I easily get an actor field's runtime values from a specific database?

Re: Unable to get actor field.

Posted: Thu Sep 17, 2020 8:37 pm
by Tony Li
Hi Justin,

If you want to be able to get and set field values at runtime, you'll need to tell the Dialogue System to add the database to the runtime Lua environment. Use the DialogueManager.AddDatabase() C# method or an Extra Databases component to do this.

If you only want to read data from the database, you only need a reference to the database. Then find the actor and read its fields directly from the database instead of accessing Lua. Example:

Code: Select all

public DialogueDatabase anotherDatabase; // Assume it's assigned in the inspector.
...
Actor actor = anotherDatabase.GetActor("Enemy1");
int damageAmount = actor.LookupInt("Attack");

Re: Unable to get actor field.

Posted: Thu Sep 17, 2020 8:53 pm
by MOTYSHIZ
Hi Tony,

Thank you very much. That was a quicker reply than I expected!
I was unaware of the Extra Databases component, and it looks like a simpler solution than what I was about to try.
I just added the Extra Databases component to my battle manager, as well as references to my enemy and friendly party databases. It worked like a charm!

Thanks,
Justin

Re: Unable to get actor field.

Posted: Thu Sep 17, 2020 8:58 pm
by Tony Li
Great! Glad I could help.