The "gt_hb3" trigger has only has one event: to say "hello world" in chat.
UI-Display"hello world"for(Allplayers)toChatarea
The problem is that the trigger will activate when ANY UNIT changes health.
Now the reason I come up with the assumption that arrays don't work is because when you use a regular variable in the add event function:
Now the code works...
I don't understand how to make arrays work in add even function.
What I'm trying to do
I'm trying to create a custom boss bar. I have a function that when called will create a boss bar user interface component on the screen.
The function will also add an event (Unit property changes) to a trigger that updates the custom boss bar.
The function creates a boss bar for any unit that contains health, shield, energy, experience, level, name, and portrait information which is why I don't just use the pre-made boss bar. This is more like a unit status bar.
I would really like to use an array, but if all fails I guess I'll have to make many variables.
Thank you for your help.
BTW, the reason I need arrays is to create a unit bar for each player like so:
Out of curiosity: Why do you use UnitRefFromVariable over UnitRefFromUnit? The latter should not have any problems whatsoever with an array variable.
The only reason to pick UnitRefFromVariable I could think of would be, that it updates the unit reference to the new unit, if you change the variable dynamically (does it? just guessing here), but that would cause your current solution to malfunction, wouldn't it?
I'm actually fairly new to SC2 editor so I'm not sure what "UnitRefFromUnit" function does.
Actually I have new problems in my trigger on the lines of what you just stated. When I change the variable reference to a new unit, the trigger will fire upon the new unit's life changing and the old unit's unit bar will not update. I have no idea how to go about doing this now.
How would I go about using "UnitRefFromUnit" instead?
At the moment it seems that I will have to create a new variable for every player's hero, like so:
UnitRefFromUnit would be used about the same way, just that you don't use a string matching the variable name, but the variable itself (so basically, same thing but no ""):
Also, your further problem confirmed, what I was suspecting earlier, the unit reference for UnitRefFromVariable gets updated, if you change the value of the variable. This is probably useful for stuff like repicking, you wouldn't need to add a new event/trigger for the replaced unit.
If you use triggers instead of pure galaxy you can't fix this...
the array is empty on startup
initTriggers() is called while the array is still empty
the event is now registered to null aka any unit
initialising the array in a map init trigger comes way to late
edit: I was wrong, you can add the event later after the init in a custom script section with the array and it works
hello, I am using triggers for the most part but I have a custom script snippet in my code for the "TriggerAddEventUnitProperty" functionality.
My script looks like this
The "gt_hb3" trigger has only has one event: to say "hello world" in chat.
The problem is that the trigger will activate when ANY UNIT changes health. Now the reason I come up with the assumption that arrays don't work is because when you use a regular variable in the add event function:
Now the code works... I don't understand how to make arrays work in add even function.
What I'm trying to do I'm trying to create a custom boss bar. I have a function that when called will create a boss bar user interface component on the screen. The function will also add an event (Unit property changes) to a trigger that updates the custom boss bar. The function creates a boss bar for any unit that contains health, shield, energy, experience, level, name, and portrait information which is why I don't just use the pre-made boss bar. This is more like a unit status bar.
I would really like to use an array, but if all fails I guess I'll have to make many variables.
Thank you for your help.
BTW, the reason I need arrays is to create a unit bar for each player like so:
never-mind I fixed it immediately, I simply put the array value into a temporary variable and used that.
here is the fix for the code in the very beginning:
I hope this helps someone else.
EDIT: THE SOLUTION I POSTED DOES NOT WORK, READ MY NEXT POST! I STILL NEED HELP.
Out of curiosity: Why do you use UnitRefFromVariable over UnitRefFromUnit? The latter should not have any problems whatsoever with an array variable.
The only reason to pick UnitRefFromVariable I could think of would be, that it updates the unit reference to the new unit, if you change the variable dynamically (does it? just guessing here), but that would cause your current solution to malfunction, wouldn't it?
@Kueken531: Go
I'm actually fairly new to SC2 editor so I'm not sure what "UnitRefFromUnit" function does.
Actually I have new problems in my trigger on the lines of what you just stated. When I change the variable reference to a new unit, the trigger will fire upon the new unit's life changing and the old unit's unit bar will not update. I have no idea how to go about doing this now.
How would I go about using "UnitRefFromUnit" instead?
At the moment it seems that I will have to create a new variable for every player's hero, like so:
if I use:
then the trigger "gt_hb3" will only activate when the health of the last stalker created changes. I actually have not solved this at all yet.
EDIT: Fixed it again!
It seems one can pass an array value. I just forgot to convert the integer into a string so the wrong key for the array kept getting passed. Yahoo!!
UnitRefFromUnit would be used about the same way, just that you don't use a string matching the variable name, but the variable itself (so basically, same thing but no ""):
Also, your further problem confirmed, what I was suspecting earlier, the unit reference for UnitRefFromVariable gets updated, if you change the value of the variable. This is probably useful for stuff like repicking, you wouldn't need to add a new event/trigger for the replaced unit.
Thank you very much Kueken!
Problem completely solved now. I was able to remove the string reference and now the game works perfectly.
Damn...
If you use triggers instead of pure galaxy you can't fix this...
the array is empty on startup
initTriggers() is called while the array is still empty
the event is now registered to null aka any unit
initialising the array in a map init trigger comes way to late
edit: I was wrong, you can add the event later after the init in a custom script section with the array and it works