Original Discord Post by phoenifox. | 2024-08-29 07:22:30
If I created some variables in the AI Character class. For example, AI Character named Jack has a float variable ‘Cash’ represents how many cash on him. Is there anyway to let the AI get the variable and tell me the value of the variable?
I do have a solution in my mind and tried it, it works. I know the AI character can get information from Objects and characters in enviroment. So I created an actor in world add added it to the AI’s Object list. I named the actor as ‘Jack’s Information’. And for the information of the actor, I added ‘This is Jack’s Information. He got 1000 cash on him, and he has a lollipop on him.’. After done that, the character can tell me how much cash on him and when I ask what else on him, he also answered that he got a lollipop. It works, but I want know if there are a better way to do it.
Hello <@306798908116303892>,
You’ve found a clever workaround! Instead of creating and managing a new actor, you could use setters for the variables you want your AI character to access. Update the values directly and call the AddObject function from the environment. This way, your AI character will be automatically updated whenever the value changes, and you won’t need an extra actor. Check the screenshot for reference.
Reply by mighty_brute | 2024-08-29 07:59:57
Hello <@306798908116303892>,
You’ve found a clever workaround! Instead of creating and managing a new actor, you could use setters for the variables you want your AI character to access. Update the values directly and call the AddObject function from the environment. This way, your AI character will be automatically updated whenever the value changes, and you won’t need an extra actor. Check the screenshot for reference.
Reply by phoenifox. | 2024-08-29 08:42:23
Hi Brute, thank you a lot for your answer :D. It works well! I created a setter like you did and it successfully initialize the cash count for the AI. But a new question appears in my mind. Can I update the cash variables by talking to AI like, “I’ll give you 500 dollars.” I tried to create a Take Cash event to do that, by using the Setter to update the cash variable. But I find that I have no idea to get the input value for the Setter.
Based on certain events, you can pass values to the setter function, for example, using a key trigger. Then, you can use the InvokeSpeech function to make the AI character speak about it.
Additionally, you can use NarrativeTemplateKeys for this. To learn more about NarrativeTemplateKeys, you can refer to this Documentation.
Reply by mighty_brute | 2024-08-29 11:22:49
Based on certain events, you can pass values to the setter function, for example, using a key trigger. Then, you can use the InvokeSpeech function to make the AI character speak about it.
Additionally, you can use NarrativeTemplateKeys for this. To learn more about NarrativeTemplateKeys, you can refer to this Documentation.
Reply by phoenifox. | 2024-08-29 11:32:52
Thank you Brute, it is really useful. I’ll check the document and learn how to use it.
If you have any other questions, please do not hesitate to ask.
We would be very grateful if you could leave a comment on our store pages with your company name or the name of your project. We value your feedback and comments as they help us improve our services and products. https://www.unrealengine.com/marketplace/en-US/product/convai/reviews