Hey guys. I am trying to make a trigger that displays a "Low Health!" message under my hero once he dips below 200 health. The issue is that the message displays repeatedly (any time he gets hit) under 200 health. I tried adding a variable to check if the message has already been displayed but it doesn't seem to be working. Here is what my trigger looks like.
-
Events:
-Player unit takes any non fatal damage
Local Variables:
-Lowhealth <Boolean>
Conditions:
-(Player Unit Life (Current)) <= 200
-Lowhealth = false
Actions:
-Variable - Set Lowhealth = true
-Display Text Tag "Low Health!"
Ok, I got it to work by making Lowhealth into a global variable instead of a local one. So the question now is, what is the difference between a local a global variable?
A local variable is basically one that is only used in one instance of the trigger.
For example, you have 2 variables: X and Y, both integers, both set to 0 initially.
X is local.
Y is global.
Your trigger does the following:
SetX=X+1DisplayXasavalueSetY=Y+1DisplayYasavalue
After you run the trigger 5 times, you would get the following:
1.X=1Y=12.X=1Y=23.X=1Y=34.X=1Y=45.X=1Y=5
Every time the trigger runs, a new variable X is created, set to 0, then you add 1 to it. After the trigger ends, that X more or less disappears and is never used again. The Y variable is used all 5 times the trigger runs.
I see. So basically every time my trigger would go off, the local variable would be reset to its initial value, negating the change I had set under the actions.
Hey guys. I am trying to make a trigger that displays a "Low Health!" message under my hero once he dips below 200 health. The issue is that the message displays repeatedly (any time he gets hit) under 200 health. I tried adding a variable to check if the message has already been displayed but it doesn't seem to be working. Here is what my trigger looks like.
-Events: -Player unit takes any non fatal damage
Local Variables: -Lowhealth <Boolean>
Conditions: -(Player Unit Life (Current)) <= 200 -Lowhealth = false
Actions: -Variable - Set Lowhealth = true -Display Text Tag "Low Health!"
-Any suggestions?
@voodude2008: Go
Ok, I got it to work by making Lowhealth into a global variable instead of a local one. So the question now is, what is the difference between a local a global variable?
local variables can only be used in 1 trigger and/or preset action, global variables can be used in all triggers
A local variable is basically one that is only used in one instance of the trigger.
For example, you have 2 variables: X and Y, both integers, both set to 0 initially.
X is local. Y is global.
Your trigger does the following:
After you run the trigger 5 times, you would get the following:
Every time the trigger runs, a new variable X is created, set to 0, then you add 1 to it. After the trigger ends, that X more or less disappears and is never used again. The Y variable is used all 5 times the trigger runs.
@ProxyTooMuch: Go
I see. So basically every time my trigger would go off, the local variable would be reset to its initial value, negating the change I had set under the actions.
@voodude2008: Go
Almost. The local variable will be destroyed afterwards.
In other words: A local variable only exists as long as the instance in which it was created in.
Condition: Number of times trigger has been executed == 0