Page 1 of 2

Communicate with MY script?

Posted: Thu Dec 22, 2022 6:13 pm
by Hereder
Hi!

Just wonder, is there a "Cleaner" way to send "commands/data" from the Conversation to my own script?
In this example, The lady I talk to will either Like me or Dislike me based on what I say.
But I need that Like/Dislike choice to send "Data" to my own script so I can store it and remember how much she likes me/dislikes me in the future.

I also want to spawn a "Heart" above her head when the player pick the right choice. (I've managed to chance her portrait)
How can do these things without using the Scene Event thing?
When attaching my script to the Scene Event Option, It creates this "Dialogue System Scene Events" gameobject,
and I'm afraid it will become HUGE later on and maybe performance will suffer. Also, If I have to attach the Script all the time I feel like it will take too much time.

So, is there a cleaner way of doing this? Like, Can I attach the Script to the Actor (In the Actor menu) and all Public Void options from my Script will pop up in the Sequence, Conditions or Script Field? If that make sense...

Thanks!

Re: Communicate with MY script?

Posted: Thu Dec 22, 2022 7:06 pm
by Tony Li
Hi,

Please see this tutorial: How to Connect Your Own Code to Lua (video)

And/or write custom sequencer commands. Cutscene Sequence Tutorials

Re: Communicate with MY script?

Posted: Fri Dec 23, 2022 1:37 am
by Hereder
Thank you!
I think I got it! It works and I can see how to use it in other types of cenarious.
But could you pls help to re-write this one to only call whatever is in the public void?

[
public void GiveXP(double amount)
{
npcCharacter.IncreaseRelationship(0.1f); <---- I only need to call this one. But if I delete double amount i get error futher down...
}

Here

private void OnEnable()
{
Lua.RegisterFunction("GiveXP", this, SymbolExtensions.GetMethodInfo(() => GiveXP((double)0))); <--- This one I don't know how to write in order to just do whatever is inside the public void function...
}


That way I add anything I want inside that public void function, the examples given in the video was a bit complicated.
However I think I know how to use the String function, so that was good!

Re: Communicate with MY script?

Posted: Fri Dec 23, 2022 7:36 am
by Tony Li
Hi,

Try this:

Code: Select all

private void OnEnable()
{
    Lua.RegisterFunction(nameof(IncreaseRelationship), this, SymbolExtensions.GetMethodInfo(() => IncreaseRelationship()));
}

public void IncreaseRelationship()
{
    npcCharacter.IncreaseRelationship(0.1f);
}
Keep in mind that Lua functions are registered globally. You can't register the same function name on multiple GameObjects.

Re: Communicate with MY script?

Posted: Fri Dec 23, 2022 8:49 am
by Hereder
All right! Good to know, I will give it ago!

Re: Communicate with MY script?

Posted: Fri Dec 23, 2022 8:55 am
by Hereder
Tony Li wrote: Fri Dec 23, 2022 7:36 am Hi,

Try this:

Code: Select all

private void OnEnable()
{
    Lua.RegisterFunction(nameof(IncreaseRelationship), this, SymbolExtensions.GetMethodInfo(() => IncreaseRelationship()));
}

public void IncreaseRelationship()
{
    npcCharacter.IncreaseRelationship(0.1f);
}
Keep in mind that Lua functions are registered globally. You can't register the same function name on multiple GameObjects.
Just one question with this method. What do I type in the ComstumLuaFunctionInfo?
I assume I need to type it in there in order for it to appear in the Dialouge System ->Quests -> + -> Costum -> _____?

EDIT: It did show up after restarding... But I get an error Dialogue System: Lua code 'IncreaseRelationship(0)' threw exception 'Number of parameters specified does not match the expected number.'...

I will look around some more and see if I can find a solution

EDIT Again. I set it to NONE in the ComstumLuaFunctionInfo - so now it will run the code that is inside the public void :)
Thank you so much!

Re: Communicate with MY script?

Posted: Fri Dec 23, 2022 10:05 am
by Tony Li
Glad to help!

Re: Communicate with MY script?

Posted: Sat Dec 24, 2022 12:38 am
by Hereder
Tony Li wrote: Fri Dec 23, 2022 10:05 amGlad to help!
Hai, but I noticed that it update "Hearts" to all characters. as you said, its global and effects everythng.
Need to find away around that, but I think it can be handled in my own script.
Thansk for the help!

Re: Communicate with MY script?

Posted: Sat Dec 24, 2022 8:16 am
by Tony Li
Hi,

Here are some ideas to handle that.

1. In your IncreaseRelationship(double) method, use DialogueManager.currentConversant. This property points to the conversation conversant (e.g., the NPC). Example:

Code: Select all

public void IncreaseRelationship(double amount)
{
    if (DialogueManager.currentConversant == null) return; // If there's no conversant, do nothing.
    var hearts = DialogueManager.currentConversant.GetComponent<Hearts>(); // Get Hearts component.
    if (hearts != null) hearts.value += (float)amount; // Increase value.
}

2. Or specify a character name in IncreaseRelationship:

Code: Select all

public void IncreaseRelationship(string characterName, double amount)
{
    var characterGameObject = GameObject.Find(characterName);
    if (characterGameObject == null) return;
    var hearts = characterGameObject.GetComponent<Hearts>(); // Get Hearts component.
    if (hearts != null) hearts.value += (float)amount; // Increase value.
}

Re: Communicate with MY script?

Posted: Mon Dec 26, 2022 2:56 am
by Hereder
Thanks alot!
Will try!

Before I post a new question in the forums... Is it possible to change the Dialouge ID number after the fact?
I made a Dialouge tree that is a bit... all over the place and kept adding things to it. So the Dialouge Entry ID is really... All over the place :P It will be difficult to translate the game later on I thought!

Btw, in the example you gave me, does theis DIalouge System have a build in "heart system"?