How can I access node fieid vaule by using script

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
rahsu123
Posts: 7
Joined: Sat Nov 23, 2024 12:12 am

How can I access node fieid vaule by using script

Post by rahsu123 »

hi there:
This issue has been bothering me for several days. Could you please advise me on how to read and write my custom node fields in the script? I tried to do it as shown in the picture below, but it was not correct. I look forward to your clarification.
Attachments
img_v3_02gt_10bf1858-586e-4bcc-b229-394f5b632c5g.jpg
img_v3_02gt_10bf1858-586e-4bcc-b229-394f5b632c5g.jpg (196.81 KiB) Viewed 868 times
User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: How can I access node fieid vaule by using script

Post by Tony Li »

Hi,

To conserve memory, dialogue entry fields are not represented in Lua, so you can't access them directly in Conditions and Script fields. This is different from Actor and Quest fields, which you can access like:

Code: Select all

Quest["Get_the_Launch_Codes"].Description = "This is the new description for this quest."
Instead, you can access dialogue entry fields in C#. Example:

Code: Select all

private DialogueEntry currentEntry;

// The Dialogue System automatically calls this special method. This script must be
// on the Dialogue Manager or its children. We record the current entry here.
void OnPrepareConversationLine(DialogueEntry entry) { currentEntry = entry; }

bool abilityCheck()
{
    string ability = Field.LookupValue(entry.fields, "ability");
    float probability = Field.LookupFloat(entry.fields, "probability");
    float dieRoll = Random.Range(0, 100) + GetPlayerStat(ability); //(just example code)
    return dieRoll < probability;
}
Then you can register the abilityCheck() method with Lua:

Code: Select all

void Awake() 
{
    Lua.RegisterFunction(nameof(abilityCheck), this, SymbolExtensions.GetMethodInfo(() => abilityCheck()));
}
So you can call it in a dialogue entry's Script field:
  • Script: Variable["checkPoint1"] = abilityCheck()
rahsu123
Posts: 7
Joined: Sat Nov 23, 2024 12:12 am

Re: How can I access node fieid vaule by using script

Post by rahsu123 »

Thank you for your advice,it has resolved my issue effectively. Have a wonderful day!
User avatar
Tony Li
Posts: 22655
Joined: Thu Jul 18, 2013 1:27 pm

Re: How can I access node fieid vaule by using script

Post by Tony Li »

Glad to help!
Post Reply