Communicate with MY script?
Communicate with MY script?
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!
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!
- Attachments
-
- increesLove.png (105.35 KiB) Viewed 650 times
Re: Communicate with MY script?
Hi,
Please see this tutorial: How to Connect Your Own Code to Lua (video)
And/or write custom sequencer commands. Cutscene Sequence Tutorials
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?
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!
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?
Hi,
Try this:
Keep in mind that Lua functions are registered globally. You can't register the same function name on multiple GameObjects.
Try this:
Code: Select all
private void OnEnable()
{
Lua.RegisterFunction(nameof(IncreaseRelationship), this, SymbolExtensions.GetMethodInfo(() => IncreaseRelationship()));
}
public void IncreaseRelationship()
{
npcCharacter.IncreaseRelationship(0.1f);
}
Re: Communicate with MY script?
All right! Good to know, I will give it ago!
Re: Communicate with MY script?
Just one question with this method. What do I type in the ComstumLuaFunctionInfo?Tony Li wrote: ↑Fri Dec 23, 2022 7:36 am Hi,
Try this:
Keep in mind that Lua functions are registered globally. You can't register the same function name on multiple GameObjects.Code: Select all
private void OnEnable() { Lua.RegisterFunction(nameof(IncreaseRelationship), this, SymbolExtensions.GetMethodInfo(() => IncreaseRelationship())); } public void IncreaseRelationship() { npcCharacter.IncreaseRelationship(0.1f); }
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?
Glad to help!
Re: Communicate with MY script?
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:
2. Or specify a character name in IncreaseRelationship:
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?
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 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"?
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 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"?