Page 1 of 1

How to check for another script variable?

Posted: Sun Mar 28, 2021 3:12 pm
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

Re: How to check for another script variable?

Posted: Sun Mar 28, 2021 4:19 pm
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).


Re: How to check for another script variable?

Posted: Sun Mar 28, 2021 5:11 pm
by AHAKuo
Thank you! This is helpful :)

Re: How to check for another script variable?

Posted: Sun Mar 28, 2021 5:36 pm
by Tony Li
Happy to help!