How to check for another script variable?

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
AHAKuo
Posts: 8
Joined: Sat Dec 05, 2020 12:41 pm

How to check for another script variable?

Post by AHAKuo »

Hi there!

I'm loving this tool, but I want a way to be able to use conditions from the scene rather than just the Lua variables. I tried placing gameobjects that kept updating a lua variable whenever something was true, but that is very complicated. Is there a way to directly check a variable from another script?

For example, I want to check if a player has X amount of health and that is in another script called PlayerInfo.cs. How do I check its value directly from the dialogue and change conversations based on that?

Thank you
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to check for another script variable?

Post by Tony Li »

Hi,

Write a method that returns the health. Example:

Code: Select all

public int health;
public int GetHealth() { return health; }
Then register that method with Lua so you can use it in Conditions and Script fields (and wherever else you use Lua expressions).

AHAKuo
Posts: 8
Joined: Sat Dec 05, 2020 12:41 pm

Re: How to check for another script variable?

Post by AHAKuo »

Thank you! This is helpful :)
User avatar
Tony Li
Posts: 22112
Joined: Thu Jul 18, 2013 1:27 pm

Re: How to check for another script variable?

Post by Tony Li »

Happy to help!
Post Reply