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.
How can I access node fieid vaule by using script
How can I access node fieid vaule by using script
- Attachments
-
- img_v3_02gt_10bf1858-586e-4bcc-b229-394f5b632c5g.jpg (196.81 KiB) Viewed 868 times
Re: How can I access node fieid vaule by using script
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:
Instead, you can access dialogue entry fields in C#. Example:
Then you can register the abilityCheck() method with Lua:
So you can call it in a dialogue entry's Script field:
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."
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;
}
Code: Select all
void Awake()
{
Lua.RegisterFunction(nameof(abilityCheck), this, SymbolExtensions.GetMethodInfo(() => abilityCheck()));
}
- Script: Variable["checkPoint1"] = abilityCheck()
Re: How can I access node fieid vaule by using script
Thank you for your advice,it has resolved my issue effectively. Have a wonderful day!
Re: How can I access node fieid vaule by using script
Glad to help!