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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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