Guide how to use variables and custom scripts.

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
The point of this guide is to show variables and custom scripts in example triggers and teach those, who don't know how to set up variables and how to use custom scripts.

I am going to show you how to use most used custom scripts and variables in real triggers.

I recommend:

Variables in Detail - Daelin
Variables and Arrays - Laika.
Basic Variables - MrApples
Memory leaks and custom scripts - Emjlr3

Lets get started.

Unit&String Variables in a trigger.

This trigger stores the casting unit, target unit of ability being cast and a string. Then it shows the target unit of ability being cast the string.

StringUnit.jpg


Cast_Banish_string.jpg


Unit&Real Variables in a trigger.

This trigger stores the casting unit, target unit of ability being cast and the life of the casting unit. Then it sets the life of target unit of ability being cast to half of the stored real value. (Life of the casting value). Reals can have decimals.

RealUnit.jpg


Unit&Point variables plus Custom Scripts in a trigger.

Firstly, this trigger declares locals, then it stores the casting unit and the target point of ability being cast. Then it creates one captain at the position of the target point of ability being cast and fianlly removes the location leak. The local unit variable has to be nulled in the end.

PointUnit.jpg


Unit&Integer Variables in a trigger.

This trigger stores the casting unit and gives him the level of the casting unit times 10 bonus Xp in addition to his current xp. Integers cannot have decimels.

integerwhoops.jpg


Unit Group&Point variables plus Custom Scripts in a trigger.

This trigger stores the target point of ability being cast and picks all units in the set unit group. Unit groups leak, so we have to take care of the leaks with a custom script and as well use a custom script to fix the location leak.

UnitGroup.jpg


Alternatevely the same trigger:

UnitGroupAlternative.jpg


This trigger adds a hero to a unit group after it died.

UnitGroup2.jpg


Then another trigger revives all the units in the unit group and removes all the unit from it every 30 seconds.

unitgroupfix.jpg


There is alot of functions in the unit group category, go and check them out.

UnitGroupActions.jpg


Player Group variables in a trigger.

This trigger adds player Red and Blue to Player group 1 and Teal, Purpel to player group 2.

PlayerGroup.jpg


Then, every 15 seconds, player group 1 recieves 50 gold and player group 2 50 wood.

PlayerGroupDo.jpg


Discover the other player group functions aswell.

PlayerGroupActions.jpg


Item&Point variables plus Custom Scripts in a trigger.

If a unit dies, it decalares locals, and stores the position of the the dying unit. Then, it creates an item at the position of the died unit, removes the leak with a custom script and stores the last created item. After 120 seconds, it makes the item undroppable.

item_fix.jpg


Special Effect&Point variables plus Custom Scripts in a trigger.

Firstly, it stores the target point of ability being cast, then it creates 10 a special effects in a circle using an integer loop. (TFT) After few seconds, it uses the integer loop again to destroy the special effects, removing the special effect memory leaks and fianlly it fixes the location leak.

specialeffectwhoops.jpg


Blue_Circle_special_effect.jpg


Dialog&Dialog Buttons Variables in a trigger.

Firstly, it creates a dialog with 2 buttons and sets the buttons into the variables and then shows the dialog.

Dialog.jpg


If the player has made the choice, the trigger makes sure which button was pressed and does the right action(s).

dialogbuttons.jpg


I hope these example triggers gave you some experience and knowhow how to set up and use variables and custom scripts in triggers. Updates coming soon. Feedback appriciated.
 

Zoxc

New Member
Reaction score
13
PointUnit.jpg

You need to null the location there.


Set the locals to null here:
UnitGroup.jpg

itemwhoops2.jpg


_________________________

UnitGroup2Do.jpg

Put the remove all units in the unit group out of the loop.


specialeffectwhoops.jpg

You need to use locals for the point and the effects here. Move the RemoveLocation up after the first loop.


Also you set a unit to a variable sometimes... You should drop that.
 

corvusHaunt

New Member
Reaction score
96
All the eplanation has been done before, but the example triggers are nice, and good job cleaning up leaks.

Instead of using a group variable, you can also use this custom script right before you do "Pick every unit in...":

Code:
Custom script:    set bj_wantDestroyGroup=true
Unit Group- Pick every unit in...

Here is the code behind "Pick every unit in...":

Code:
function ForGroupBJ takes group whichGroup, code callback returns nothing
    local boolean wantDestroy = bj_wantDestroyGroup
    set bj_wantDestroyGroup = false

    call ForGroup(whichGroup, callback) [COLOR=DimGray]//This is the "And do..."[/COLOR]

    if (wantDestroy) then  [COLOR=DimGray]//if bj_wantDestroyGroup was set to true, then destroy the group[/COLOR]
        call DestroyGroup(whichGroup)
    endif
endfunction
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Zoxc said:

Set the locals to null here:
[IMG]http://i69.photobucket.com/albums/i69/Andrewgosu/UnitGroup.jpg

There are no locals in that trigger.

Zoxc said:

I didnt make it MUI on purpose.

Zoxc said:

Also you set a unit to a variable sometimes... You should drop that.[/QUOTE]

After waits, casting unit and target unit tends to get lost. a few days ago agent paper had a big trouble with it. He didnt use variables but the casting unit and target unit of ability got lost. Hedidnt had even waits. Its better to set the casting unit to find the mistake later. In my opinion:)

[QUOTE=corvusHaunt]
[CODE]Custom script: set bj_wantDestroyGroup=true
Unit Group- Pick every unit in...[/CODE][/QUOTE]

I wanted to add that, but after I load 19 images at a time to a image hosting site, Its hard to navigate and I missed that. Ill add it now.
 

Arkan

Nobody rides for free
Reaction score
92
I have a question; if you define a local location for eg. and want to clean it up after using it, is "call RemoveLocation (x)" and "set x = null" the same thing? Which one should I use?
 

corvusHaunt

New Member
Reaction score
96
They are not the same thing. I'll make up yet another diagramy comparison thingy :D

Think of a variable as a sign, that points to something. If we didn't have that sign, then we couldn't use the thing. Now, if we create location x, we have a sign pointing to a location and the sign reads "x". Whenever we need to use that location, we look at the sign labeled "x", and it points us to what we want. If we null x, or destroy the sign, we no longer can find that location. Therefore, we can't destroy it. So, we need to destroy the location first. But the sign is still there, pointing to nowhere...but it's still there taking up space, so we null it.

Hope that cleared things up rather than muddy them up :p
 

Arkan

Nobody rides for free
Reaction score
92
So you are saying I should first use RemoveLocation and after that set x = null?
And the same for Unit Groups like DestroyGroup(y) and then set y = null?
 
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