'Target unit of ability being cast'

Bananarama1

Member
Reaction score
3
Hey there!

So this is my trigger:


Code:
Breeding
    Events
        Unit - A unit Starts the effect of an ability
    Conditions
        (Ability being cast) Equal to Breed
    Actions
        Set Breedchance = (Random integer number between 1 and 10)
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                (Unit-type of (Triggering unit)) Equal to (Unit-type of (Target unit of ability being cast))
            Then - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        Breedchance Greater than or equal to 6
                    Then - Actions
                        Unit - Pause (Triggering unit)
                        Unit - Pause (Target unit of ability being cast)
                        Unit - Make (Target unit of ability being cast) face (Facing of (Triggering unit)) over 1.00 seconds
                        Special Effect - Create a special effect at (Position of (Triggering unit)) using Abilities\Spells\Orc\Devour\DevourEffectArt.mdl
                        Animation - Play (Triggering unit)'s attack animation
                        Wait 2.00 seconds
                        Special Effect - Create a special effect at (Position of (Triggering unit)) using Abilities\Spells\Orc\Devour\DevourEffectArt.mdl
                        Animation - Play (Triggering unit)'s attack animation
                        Wait 2.00 seconds
                        Special Effect - Create a special effect at (Position of (Triggering unit)) using Abilities\Spells\Orc\Devour\DevourEffectArt.mdl
                        Animation - Play (Triggering unit)'s attack animation
                        Wait 2.00 seconds
                        Special Effect - Create a special effect at (Position of (Triggering unit)) using Abilities\Spells\Orc\Devour\DevourEffectArt.mdl
                        Animation - Play (Triggering unit)'s attack animation
                        Wait 2.00 seconds
                        Special Effect - Create a special effect at (Position of (Triggering unit)) using Abilities\Spells\Orc\Devour\DevourEffectArt.mdl
                        Animation - Play (Triggering unit)'s attack animation
                        Wait 2.00 seconds
                        Unit - Unpause (Target unit of ability being cast)
                        Unit - Unpause (Triggering unit)
                        Special Effect - Create a special effect at (Position of (Triggering unit)) using Abilities\Spells\Orc\Devour\DevourEffectArt.mdl
                        Game - Display to (Player group((Owner of (Triggering unit)))) the text: |cff32cd32Breeding ...
                        Unit - Create 1 (Unit-type of (Triggering unit)) for (Owner of (Triggering unit)) at (Position of (Triggering unit)) facing Default building facing degrees
                    Else - Actions
                        Game - Display to (Player group((Owner of (Triggering unit)))) the text: |cffff0000Breeding ...
            Else - Actions
                Game - Display to (Player group((Owner of (Triggering unit)))) the text: |cffff0000Breeding ...

My problem is that the last 'Unpause' for 'Target unit of ability being cast' does not work, nor did any special effects I placed at the point of the target unit (I took those out). For some reason, the first pause does, but by the time it gets to the unpausing, the trigger has forgotten what unit 'target unit of ability being cast' is. I cannot just save the unit as a variable because lots of units could be doing this ability at the same time (don't even ask, I know the trigger/ability looks a bit weird :L).

So say I saved the target unit as a variable, 'Breedee' and used that in this trigger. If this trigger ran again at the same time, surely the 'Breedee' variable would only apply to the latest running of the trigger, so any of them that started before would not have the 'Breedee' variable saved to them, and all the new units spawned would appear at the last one to finish breeding, and the first 'Breedee's would be stuck as paused units. Is that right?

And yes, I know this trigger leaks like the titanic, it's only a hypothetical thing I whipped up for my map, if it actually worked I would clean it up after, but right now I am more focused on the actual function of the trigger being successful! xD
 

Imp Midna

Active Member
Reaction score
52
Hey there!
So say I saved the target unit as a variable, 'Breedee' and used that in this trigger. If this trigger ran again at the same time, surely the 'Breedee' variable would only apply to the latest running of the trigger, so any of them that started before would not have the 'Breedee' variable saved to them, and all the new units spawned would appear at the last one to finish breeding, and the first 'Breedee's would be stuck as paused units. Is that right?
The exactly same thing happens when you use target unit of ability beeing cast. It will change the next time any skill is casted, which is what happens during your waits i asume. Thus, you should not use it after a wait. Triggering unit is the only thing that always works, even after waits.

And yes, I know this trigger leaks like the titanic
lol

That is the common problem with making spells mui, and quite easy to solve using a local variable. local variables are unique for every call of your function (aka trigger). Using local variables in the GUI works like this:
Trigger:
  • Actions
    • Custom Script: local unit udg_Breedee
    • Set Breedee = (Target unit of Ability beeing cast)
    • Unit - Pause (Breedee)
    • Wait (some seconds)
    • Unit - Unpause (Breedee)

On this way, Breedee wont be changed if another unit casts the spell, the new caster will get his own breedee variable. note that the variable will not work anymore in another function (inside a pick every unit and do block, for each integer and ifs work though)
 

Bananarama1

Member
Reaction score
3
Ahh yes, the local variable thing did come up in my research :D Someone on HW said the same thing, so I'm genna try to make it work with locals as soon as I can get onto my WE computer :)

Cheers!
 

GardenofWar

You can change this now in User CP.
Reaction score
2
I'm trying to understand this correctly, and if I do, I believe this could save me a lot of time. So simply by making that custom script before you set a variable, giving it the udg_variablenamehere, will allow it to be assigned to multiple instances and wont reassign that variable to the next thing that would proc it? It like makes an array of that variable type and assigns those somehow?
 

Imp Midna

Active Member
Reaction score
52
Thats what its doing. Keep in mind that its only valid inside the function (which means you will address you actual global variable again if you enter a "condition" block or the "actions" block of a "pick every something" instruction.)
 

GardenofWar

You can change this now in User CP.
Reaction score
2
Please forgive me here, I'm not a fast learner but I try to understand the principle of things, then I never forget them. I'm not exactly sure what you are saying here. Are you saying that the variable is only accessed in the trigger that it's created within. That makes sense since there is no way to know which array of that variable it has made and assigned to which instance? Is that what you are saying?
 

Imp Midna

Active Member
Reaction score
52
Well, if you want to know things precisely, ill spend some time here.

Warcraft 3's scripting language is JASS, and like most programming languages known to mankind, JASS uses functions to archive its goal. A function is a collection of actions (variable sets and calls of over functions). Every action you can add using "add action" in the GUI is a function call in JASS (except for set variable). Everything you put in the "Actions" part of a trigger is a huge function. Every Set of Conditions is translated into a function. Taking a look at a basic trigger:
Trigger:
  • Trigger
    • Events
      • Unit - A unit Dies
    • Conditions
      • (Unit-type of (Triggering unit)) Gleich Worker
    • Actions
      • Game - Display to (All players) the text: You lost a worker!

Everything you see in here basically shrouds a shittons of function calls. In Jass, this trigger looks like this (dont worry, its not complicated, you only need to read the green lines starting with a "//")
JASS:
//As you can see, this line begins with "function". Everything between this line and the next
//"endfunction" is a function. As you can tell by the name (Trig_Trigger_Conditions), this function is
//what the "Conditions" Block of our GUI trigger became.
function Trig_Trigger_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'hpea' ) ) then
        return false
    endif
    return true
endfunction
 
//another function. This is the function that our "Actions" became.
function Trig_Trigger_Actions takes nothing returns nothing
    //and it calls another function called "DisplayTextToForce" which - he? - displays text to a force
    //(force is a playergroup)
    //GetPlayersAll() ALSO is a function
    call DisplayTextToForce( GetPlayersAll(), "TRIGSTR_001" )
endfunction

//===========================================================================
//this is the function that our Events-Block became.
function InitTrig_Trigger takes nothing returns nothing
    set gg_trg_Trigger = CreateTrigger(  )
    //more function calls, this time with awfully long stupid names nobody really can memorise
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Trigger, EVENT_PLAYER_UNIT_DEATH )
    call TriggerAddCondition( gg_trg_Trigger, Condition( function Trig_Trigger_Conditions ) )
    call TriggerAddAction( gg_trg_Trigger, function Trig_Trigger_Actions )
endfunction


As you can see, a lot of functions.

As allready mentioned, functions are a list of actions (variable sets or function calls) including flow control (which is a complex-sounding therm for "if's" and lops (for example the for loop you know from the GUI)). Functions are made to fulfill repeating tasks. The actions block of a Trigger is one task (in our Example, the task is "showing that the player lost a worker"). And its repeating, as it has to be done every time a worker dies. To do this, you have a function that shows the message, and its called automatically by the game every time a worker dies. (the event - a unit dies) The Conditions function is also a task (checking if its a unit of the type "worker") and has to be executed every time a unit dies.
Due to strange limitations you need deeper understanding of jass to really understand, every "pick every something"-actions block gets its own function, while for-loops and if-s dont. Just keep it in mind this way.
So far about the theory of functions.

Now, functions sometimes need a way to store data. We have 2 ways to do this:
- global variables. these can be accessed from EVERYWHERE in the ENTIRE programm (map).
- local variables. these variables are only accessible in a certain room. When they exit this room, they are automatically destroyed. Due to more strange limitations (read: the lazyness of the developers of this awfull language called "jass"), these "rooms" are only one thing: a function.
So, in jass, a local variable is a variable, that can be accessed INSIDE a function ONLY. How this variable is actually stored in the memory is not known to me, as youre not actually programming (jass is NOT a programming language), and blizzard could just as well have decided to store it in a huge array if their personal wheel of fortune points at 600$, somewhere on your hard disk if it points to lose a turn and... you get the idea.
What we DO know though is that the variable is somehow linked to the function its executed in, and that every call of this function gets its own local variable that can only be accessed from this function.

Due to strange limitations, local variables are NOT available in the GUI of the editor. What we did in this threat to actually use them is a mean trick:

to easily distinguish global variables from everything else, they start with an udg_. When we create a global variable (lets call it "Name"), its actually called "udg_Name". When we use
Trigger:
  • Game - Display to (All players) the text: Name

it translates to
JASS:
call DisplayTextToForce( GetPlayersAll(), udg_Name )

(note: its udg_Name).
if we now write
Trigger:
  • Custom script: local string udg_Name

we create a new local variable (a variable which is only valid in this function, see above) with the name "udg_Name". Now we have 2 variables, the local variable we just created, and the global variable with the exact same name. If we now write
Trigger:
  • Game - Display to (All players) the text: Name

(or how it looks in JASS)
JASS:
call DisplayTextToForce( GetPlayersAll(), udg_Name )

which variable should he take? the global or the local one? As a rule, he should take the one with the smaller "room" in which its valid, which is the local one. So, now, whenever we use your global variable Name, we actually use the local variable, the one that is only valid inside the function and from which every call has its own instance (cant mention that often enough). We do NOT touch the actual global variable on any way anymore. And because we only use the local variable now, and because the local variable has those infamous properties, which is that its only valid inside the function and that every call gets its own unique local variable (yehaw), it will not change after a wait (to do that, something would have to access your local variable, but the local variable is -infamous property - only valid inside the function, which is sleeping, so...) and your trigger will work.

And as (like mentioned above) Conditions and the Actions of a pick-every-something block use theyr own functions, your local variable does NOT work in those Condtion or Action blocks, as they have a new function and your local variable still has the infamous properties of only beeing valid and accessible inside the function it belongs to (and is unique for every call. pew).
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top