• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Variable not setting right?

Status
Not open for further replies.
Level 2
Joined
Nov 19, 2015
Messages
9
I have an issue with this trigger not setting the ‘target unit of ability being cast’ variable properly.

  • Untitled Trigger 004
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to MarkTest
    • Actions
      • Set Mark_Caster = (Triggering unit)
      • Set Mark_Targetn = (Target unit of ability being cast)
      • Unit - Order (Triggering unit) to Attack (Target unit of ability being cast)
      • Unit - Create 1 Boomerang Dummy Cast for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees
      • Unit - Hide (Last created unit)
      • Unit - Add Mark BL to (Last created unit)
      • Unit - Set level of Mark BL for (Last created unit) to (Level of Mark for (Triggering unit))
      • Unit - Order (Last created unit) to Orc Shaman - Bloodlust (Triggering unit)
      • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
      • Wait until (((Triggering unit) has buff Bloodlust) Equal to False), checking every 0.50 seconds
      • Unit - Create 1 Boomerang Dummy Cast for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees
      • Unit - Hide (Last created unit)
      • Unit - Add a 1.00 second Generic expiration timer to (Last created unit)
      • Set Mark_Caster = (Last created unit)
      • Set Mark_Target = (Last created unit)
  • mark no control
    • Events
      • Unit - A unit Is issued an order targeting an object
      • Unit - A unit Is issued an order targeting a point
      • Unit - A unit Is issued an order with no target
    • Conditions
      • (Triggering unit) Equal to Mark_Caster
    • Actions
      • Trigger - Turn off mark no control <gen>
      • Unit - Order Mark_Caster to Attack Mark_Targetn
      • Trigger - Turn on mark no control <gen>
The trigger is supposed to have a dummy cast bloodlust on the caster, then order the caster to attack the target. The caster and target are set as variables, and there's another trigger that orders the caster variable to attack the target variable whenever any order is given to the caster. After the bloodlust wears off, the variables are changed to a dummy so the second trigger doesn't trigger anymore. Obviously, it's not working and the second trigger isn't doing it's thing.

I set up a trigger to message the two variables every few seconds, and when the spell is cast the target variable doesn't show up.

The weirdest part is that if I remove the cooldown and cast the ability again before the bloodlust ends, the target unit variable does get set and the second trigger starts working. I have no idea why this happens or what the problem is. Can someone help me with this?
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
Well first off, you aren't even using the variables you made. You're still using GetTriggeringUnit() and GetSpellTargetUnit(). Not that it matters, it's just weird. The way you have your triggers is also extremely inefficient, but we can cross that bridge later.

Your second trigger is not going to order the dummy unit to attack until the original Caster doesn't have Bloodlust anymore. Do you also mind showing me how your Display - Text trigger looks like? The one that shows you your Target and or Targetn variables.
 
Last edited:
Level 2
Joined
Nov 19, 2015
Messages
9
Your second trigger is not going to order the dummy unit to attack until the original Caster doesn't have Bloodlust anymore. Do you also mind showing me how your Display - Text trigger looks like? The one that shows you your Target and or Targetn variables.

It's the caster that attacks the target, not a dummy unit. The second dummy unit is just to dump the variables. I know there's a better solution in there somewhere, it's just the one I chose as I don't think it would make the trigger not work, so I assumed it was a fine placeholder. I set the variables so they could be referenced in the second trigger. Would it be more efficient to reference the variables in the original? I didn't think it would make a difference.

Here's the display trigger.

  • CasterTest
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Game - Display to (All players) the text: (String((Unit-type of Mark_Caster)))
      • Game - Display to (All players) the text: (String((Unit-type of Mark_Targetn)))
 
It's the caster that attacks the target, not a dummy unit. The second dummy unit is just to dump the variables. I know there's a better solution in there somewhere, it's just the one I chose as I don't think it would make the trigger not work, so I assumed it was a fine placeholder. I set the variables so they could be referenced in the second trigger. Would it be more efficient to reference the variables in the original? I didn't think it would make a difference.

No, you need to use the variables, not just set them. So set your variable for casting unit and then never use (casting unit) again. Only use the variable Caster_Unit (or whatever you want to call it). The same goes for locations, targets and everything else. Also, what is the root ability of MarkTest? Does that ability target a unit?
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
It's the caster that attacks the target, not a dummy unit. The second dummy unit is just to dump the variables. I know there's a better solution in there somewhere, it's just the one I chose as I don't think it would make the trigger not work, so I assumed it was a fine placeholder.

Well that's a problem then. Mark_Caster isn't an array or local variable, meaning that it will overwrite whatever was previously there with the new one, which you do at the bottom of your trigger. You're overwriting the triggering unit with the lasted created unit, meaning that Mark_Caster is now the last created unit, not the triggering unit.


I set the variables so they could be referenced in the second trigger. Would it be more efficient to reference the variables in the original? I didn't think it would make a difference.

I've never actually ran benchmarks on it, but using variables is always faster. Every set of parantheses you see is a function call. So the more parantheses you see in a line, the more function calls.

Here's the display trigger.

  • CasterTest
    • Events
      • Time - Every 2.00 seconds of game time
    • Conditions
    • Actions
      • Game - Display to (All players) the text: (String((Unit-type of Mark_Caster)))
      • Game - Display to (All players) the text: (String((Unit-type of Mark_Targetn)))

The moment someone casts the spell, you should see the name of the Caster and it's target. However, once the caster loses its debuff, it will display the name of nothing because you made the variables Mark_Caster & Target be the last created unit, or the dummy unit.
 
Level 2
Joined
Nov 19, 2015
Messages
9
No, you need to use the variables, not just set them. So set your variable for casting unit and then never use (casting unit) again. Only use the variable Caster_Unit (or whatever you want to call it). The same goes for locations, targets and everything else. Also, what is the root ability of MarkTest? Does that ability target a unit?



I used the casting unit in the second variable. If the casting unit is set, then every time it is ordered it will be re-ordered to attack the target unit, so it's forced to attack it until the variable is changed.

The root ability is chain lightning. It used to be storm bolt, but I changed it at some point to see if it would change anything. It does target a unit, not a point.

Well that's a problem then. Mark_Caster isn't an array or local variable, meaning that it will overwrite whatever was previously there with the new one, which you do at the bottom of your trigger. You're overwriting the triggering unit with the lasted created unit, meaning that Mark_Caster is now the last created unit, not the triggering unit.




I've never actually ran benchmarks on it, but using variables is always faster. Every set of parantheses you see is a function call. So the more parantheses you see in a line, the more function calls.

At the end of the trigger (when the buff ends) the spell is over, the caster is no longer supposed to be forced to attack the target, which is why I dump the variables onto a dummy.

Thanks for the info, I'll change it.

I'm sorry, maybe my description of the spell was unclear. The caster casts the spell on a unit, get buffed with bloodlust, and is forced to attack that unit until the buff ends. The problem I have is that the effect of the caster being unable to stop attacking the unit isn't working.
 
Level 37
Joined
Jul 22, 2015
Messages
3,485
I'm sorry, maybe my description of the spell was unclear. The caster casts the spell on a unit, get buffed with bloodlust, and is forced to attack that unit until the buff ends. The problem I have is that the effect of the caster being unable to stop attacking the unit isn't working.

Oh I'm sorry, I misunderstood. So the caster is still allowed to attack other things even though it still has bloodlust?
 
Level 2
Joined
Nov 19, 2015
Messages
9
Yes, the second trigger doesn't trigger at all. Upon casting the spell, the unit is ordered to attack the target as it should, but I can still cancel it or move away.

Because the display trigger isn't showing the targetn variable, I can only assume the reason is that it's not setting for some reason.
 
Level 2
Joined
Nov 19, 2015
Messages
9
This is embarrassing. I was moving the spell onto another map to send it, but I found that it started working for some reason on the new map. The problem (I think) was that bloodlust wasn't being cast soon enough, and the check to see if the caster didn't have the buff was triggering before it was even cast. After adding a wait before the "wait until", it works fine.

... I'm still not sure why the variables were being weird in the messages. You can have a look at the map if you want, but the second trigger is working now, so the problem is solved. Thanks for the help, and the advice on making the trigger more efficient.

http://www.filedropper.com/mark_3
 
Level 22
Joined
Aug 27, 2013
Messages
3,973
I'm just correcting your triggers here.

You should use all the variable you've set before or else it will be waste of time and space. For ex:
  • Unit - Order (Triggering unit) to Attack (Target unit of ability being cast)
=>
  • Unit - Order Mark_Caster to Attack Mark_Target

Don't use wait to check whether your unit has the buff or not. Use periodical timer instead. Add your Mark_Caster to a Unit Group Variable. Then create a second trigger which checks for every 0.50 second or faster, use the If then else block and check if the unit has the buff using the boolean comparison. I don't really understand what you want to do next but I assume you want to stop your unit from attacking the target unit when the buff has worn off but keep attacking the target unit when the buff is still there so in the ITE block you can just order him to keep attacking and if he no longer has the buff, order him to stop attacking.

I hope my explanation is understandable.
 
Status
Not open for further replies.
Top