Lesson 1: GUI "General" Functions

Tonks

New Member
Reaction score
160
Do Nothing:
Often used in league with If / Then / Else functions. This, if it isn't obvious enough, does nothing. It may seem pointless, but later in this class you will learn why it's useful, as we move onto the other functions.

Comment:
Comments are used for many reasons. The most common uses are for separation and pointing things out to other people. For example, in my maps, I place comments strategically so that people with little knowledge can figure out what the functions are for.
I also sometimes use comments to visually separate different parts of a trigger. In long initialization triggers, it helps to have dividers.

Custom Script:
Possibly the most useful function in GUI. This can be used to place Jass functions within GUI Script. Common uses include Cleaning up memory leaks and calling functions not included in the GUI menu.


Terms related to Custom Script-

Memory Leak: the leakage of handle objects, or in other words, basically whenever you create something or reference something that isn't an integer, the game loses it’s location, thus causing a leaked piece of memory. Now granted these are cleaned at the end of the game, but if enough pile up during play without being removed, it can cause serious lag to the players, ranging from a little here and there, to complete un-playability, neither of which is wanted.

Jass: the scripting language used for scripting Maps and AI files in Blizzard Entertainment's Warcraft III game. Most people make triggers in GUI format, the premade template triggers that are in the World Editor. However, the actual language of these is that of JASS, which can give you almost free reign over every aspect of the game.

Custom Script: this is an action in the World Editor Trigger Editor which allows you to type one line of JASS script as opposed to using a template GUI script. This is what we will be using to clean up most of our memory leaks, since Blizzard put in the ability to remove these leaks, but neglected to add them to basic GUI.

Memory Leaks



- - - Unit Group Leaks - - -

What not to do:
Code:
Trigger
    Events
    Conditions
    Actions
        Unit Group - Pick every unit in [COLOR="Red"](Units in (Playable map area))[/COLOR] and do (Actions)
            Loop - Actions
                Unit - Kill (Picked unit)

How to do it:
Code:
Trigger
    Events
    Conditions
    Actions
        Set Temp_Group = (Units in (Playable map area))
        Unit Group - Pick every unit in Temp_Group and do (Actions)
            Loop - Actions
                Unit - Kill (Picked unit)
        Custom script:   call DestroyGroup (udg_Temp_Group)

The purpose of destroying that group variable is so that there is not stray memory floating around, not being used. Once you're finished with it, clean it up.





- - - Point Leaks - - -

What not to do:
Code:
Trigger
    Events
    Conditions
    Actions
        Unit - Create 1 Footman for Player 1 (Red) at [COLOR="Red"](Center of (Playable map area))[/COLOR] facing Default building facing degrees

How to do it:
Code:
Trigger
    Events
    Conditions
    Actions
        Set Temp_Point = (Center of (Playable map area))
        Unit - Create 1 Footman for Player 1 (Red) at Temp_Point facing Default building facing degrees
        Custom script:   call RemoveLocation (udg_Temp_Point)

Essentially what that does is creates a point at the said position, which is lost and cannot later be referenced, so it just floats around as a tempfile, lagging the game.




- - - SFX Leaks - - -

How not to do it:
Code:
Trigger
    Events
    Conditions
    Actions
        Special Effect - Create a special effect at [COLOR="Red"](Center of (Playable map area))[/COLOR] using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl

How to do it:
Code:
Trigger
    Events
    Conditions
    Actions
        Set Temp_Point = (Center of (Playable map area))
        Special Effect - Create a special effect at Temp_Point using Abilities\Spells\Human\ThunderClap\ThunderClapCaster.mdl
        Special Effect - Destroy (Last created special effect)
        Custom script:   call RemoveLocation (udg_Temp_Point)

Another way to do it:
Code:
Trigger
    Events
    Conditions
    Actions
        For each (Integer A) from 1 to 10, do (Actions)
            Loop - Actions
                Set Temp_Point = (Center of (Playable map area))
                Special Effect - Create a special effect at Temp_Point using Abilities\Spells\Undead\UnholyAura\UnholyAura.mdl
                Set Temp_SFX[(Integer A)] = (Last created special effect)
                Custom script:   call RemoveLocation (udg_Temp_Point)
        Wait 2.00 seconds
        For each (Integer A) from 1 to 10, do (Actions)
            Loop - Actions
                Special Effect - Destroy Temp_SFX[(Integer A)]

The purpose of the second 'correct' way is so that you can use waits, without losing the special effect.





- - - Unit Leaks - - -

How not to do it:
Code:
Trigger
    Events
    Conditions
    Actions
        Unit - Create 1 Dummy Caster for Player 1 (Red) at [B](Center of (Playable map area))[/B] facing Default building facing degrees

How to do it:
Code:
Trigger
    Events
    Conditions
    Actions
        Set Temp_Point = (Center of (Playable map area))
        Unit - Create 1 Dummy Caster for Player 1 (Red) at Temp_Point facing Default building facing degrees
        Custom script:   call RemoveLocation (udg_Temp_Point)
        [COLOR="Blue"]Unit - Add a 2.00 second Generic expiration timer to (Last created unit)[/COLOR]

The line in blue is if you're using this unit as a "dummy caster" to help with triggered spells. It is not necessary otherwise.




Credit goes to emjlr3 and his Custom Script and Memory Leaks Tutorial for the information.


If you have problems with Custom Script, reference this tutorial as you work:
http://www.thehelper.net/forums/showthread.php?t=27219

It's fairly comprehensive and easy to understand.


Your assignment:
Give me a trigger that changes the color of a random unit from all units to blue, then moves the unit to the center of a region. Use Custom Script to clean up leaks, and Comments to explain what you're doing with the functions.


I understand that some people may not consider this thread as very explanatory. However, I consider the best form of teaching as revision of work that one has done, rather than presenting work that one is unfamiliar with.


Please post completed work in this thread by copying your trigger as text and posting it in
Code:
 Tags.[/COLOR]
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
A piece of code, what gives one control over a specific unit? That is kind of vague.:p

Anyway, nicely explained. It should be fairly easy for beginners to follow.
 
I

IKilledKEnny

Guest
I hope it's ok that I'm posting suggestion and not an assignment.

I think this good, thanks very much for doing this and helping members however;

> other than integers

Not precisely. There are other 3 variables that doen't leak. Those are: Reals (integers that can use decimal values), booleans (return true or false) and finally strings (values that can store charecters 0-9, a-z, !?. etc.).

I would also suggest explaining that forces (but "all players") and locations leak as well.

Apart from that, it's good, basic enough, yet very informative. Thanks.
 

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
well about the memory leaks:
where are the rest of the leaks? (point,SFX,Player group,region)

about the assignment:
what exacly i need to do?
take unit and change owner?
and if yes so what leaks can be caused from that?
 

Tonks

New Member
Reaction score
160
A piece of code, what gives one control over a specific unit? That is kind of vague.:p

Anyway, nicely explained. It should be fairly easy for beginners to follow.

Changed the assignment, it was poorly explained.

> other than integers

Not precisely. There are other 3 variables that doen't leak. Those are: Reals (integers that can use decimal values), booleans (return true or false) and finally strings (values that can store charecters 0-9, a-z, !?. etc.).

I would also suggest explaining that forces (but "all players") and locations leak as well.

Apart from that, it's good, basic enough, yet very informative. Thanks.

I guess that was poorly worded; it was meant to say that other than integers, it won't leak. I'll reword it. Thanks for pointing that out.

well about the memory leaks:
where are the rest of the leaks? (point,SFX,Player group,region)

Eh, those are explained very well and clearly in the tutorial I advised you to work with. I'll copy the other important points to this thread.

about the assignment:
what exacly i need to do?
take unit and change owner?
and if yes so what leaks can be caused from that?

I changed the assignment a bit, hopefully explained it a bit more clearly.
 

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
k here's the assignment:
Code:
Assignment
    Events
        <Pick One :P>
    Conditions
    Actions
        //Setting Variables
        *Cenzored* 
       //Changing color and moving to center      
        *Cenzored*  
       //Removing Leaks
        *Cenzored*
is it A or A+? :p
 

Tonks

New Member
Reaction score
160
k here's the assignment:
Code:
Assignment
    Events
        <Pick One :P>
    Conditions
    Actions
        Set Group = (Units in (Playable map area))
        Set Unit = Random Unit from (Group)
        Set Point = (Center of (Playable Map Area))
        Unit - Change Color of Unit to Blue
        Unit - Move Unit Instantly to Point
        Custom script:    call RemoveLocation(udg_Point)
        Custom script:    call DestroyGroup(udg_Group)
is it A or A+? :p

Comments to explain what you're doing, otherwise you could have just copied it! Heh, I have nothing to fix in it. Well done.

I have included your grade in the +Rep Comment.

By the way, those people looking to just copy this, don't. Please use your own intuition to create this, so that I can give you feedback that will actually help you learn.

If anyone has questions on the subjects posted in my lessons, feel free to post them. If you don't feel comfortable posting them in public, you're welcome to PM them to me.
 

DrinkSlurm

Eat Bachelor Chow!
Reaction score
50
Here's mine

Code:
Im So Blue
    Events
        Player - Player 1 (Red) types a chat message containing -ImSoBlue as An exact match
    Conditions
    Actions
        -------- Set "tempUnitGroup" as a Unit Group variable so that it can be removed later, thus preventing a potential memory leak. --------
        Set tempUnitGroup = (Units in (Playable map area) matching ((Owner of (Matching unit)) Not equal to Player 2 (Blue)))
        -------- Set "tempUnit" as a Unit variable so that it can be referred to more than once. --------
        Set tempUnit = (Random unit from tempUnitGroup)
        -------- Set "tempPoint" as a Point variable so that it can be removed later, thus preventing a potential memory leak. --------
        Set tempPoint = (Center of (Playable map area))
        Unit - Change color of tempUnit to Blue
        Unit - Move tempUnit instantly to tempPoint
        -------- Custom script that cleans up the Unit Group variable "tempUnitGroup" that was set earlier. --------
        Custom script:   call DestroyGroup(udg_tempUnitGroup)
        -------- Custom script that cleans up the Point variable "tempPoint" that was set earlier. --------
        Custom script:   call RemoveLocation (udg_tempPoint)

(I added the condition that the picked unit that is to be changed to blue should not be owned by Player 2 Blue.)
 

Doom-Angel

Jass User (Just started using NewGen)
Reaction score
167
actually i did used my own intuition on this one i didn't even open the WE but i will edit my post so it would be hard to copy
 

DrinkSlurm

Eat Bachelor Chow!
Reaction score
50
I have a question: Is using the Comments function inside the trigger the same as using the Trigger Comments in the header above the trigger?
 

Tonks

New Member
Reaction score
160
Here's mine

Code:
Im So Blue
    Events
        Player - Player 1 (Red) types a chat message containing -ImSoBlue as An exact match
    Conditions
    Actions
        -------- Set "tempUnitGroup" as a Unit Group variable so that it can be removed later, thus preventing a potential memory leak. --------
        Set tempUnitGroup = (Units in (Playable map area) matching ((Owner of (Matching unit)) Not equal to Player 2 (Blue)))
        -------- Set "tempUnit" as a Unit variable so that it can be referred to more than once. --------
        Set tempUnit = (Random unit from tempUnitGroup)
        -------- Set "tempPoint" as a Point variable so that it can be removed later, thus preventing a potential memory leak. --------
        Set tempPoint = (Center of (Playable map area))
        Unit - Change color of tempUnit to Blue
        Unit - Move tempUnit instantly to tempPoint
        -------- Custom script that cleans up the Unit Group variable "tempUnitGroup" that was set earlier. --------
        Custom script:   call DestroyGroup(udg_tempUnitGroup)
        -------- Custom script that cleans up the Point variable "tempPoint" that was set earlier. --------
        Custom script:   call RemoveLocation (udg_tempPoint)

(I added the condition that the picked unit that is to be changed to blue should not be owned by Player 2 Blue.)

Good idea adding that condition.

Very nice work, but how would you clear the tempUnit variable?

actually i did used my own intuition on this one i didn't even open the WE but i will edit my post so it would be hard to copy

I wasn't meaning that I thought you had copied it, I was just pointing out why I wanted comments.

I have a question: Is using the Comments function inside the trigger the same as using the Trigger Comments in the header above the trigger?

No. The Comment functions inserts comments directly into the trigger, which can be moved around as other functions can. The header above the trigger is not actually part of the trigger.
 

DrinkSlurm

Eat Bachelor Chow!
Reaction score
50
Very nice work, but how would you clear the tempUnit variable?

We don't need to clear Unit variables, do we? Or do you mean to say that I should not name my variables with "temp" in front unless they are specifically for the cleaning up leaks?

No. The Comment functions inserts comments directly into the trigger, which can be moved around as other functions can. The header above the trigger is not actually part of the trigger.[/QUOTE]

So the trigger header is just another place for comments, right? It does the same thing, just in a different place.

One more quick question regarding the Custom Script: Do the spaces matter?
Code:
Custom script:   call DestroyGroup(udg_tempUnitGroup)
Custom script:   call DestroyGroup (udg_tempUnitGroup)
Custom script:   call DestroyGroup( udg_tempUnitGroup)
Custom script:   call DestroyGroup ( udg_tempUnitGroup)
All the same?
 
I

IKilledKEnny

Guest
I couldn't find any explanation about forces leaks, which are actually even worse then location leaks.

I will add my assignment (as an example more then anything else...) as soon as I get to a computer with WE.
 
U

Ur-Quan

Guest
Let do it and deserve A+

Code:
Homework1
    Events
        Time - Every 25.00 seconds of game time
    Conditions
        (Player 1 (Red) controller) Equal to User
    Actions
        -------- Setting P (Point Variable) to some point in the map so we can create units there --------
        Set P = (Random point in (Playable map area))
        -------- Creating 5 Footmen at P (random point of playable map area) --------
        Unit - Create 5 Footman for Player 1 (Red) at P facing Default building facing degrees
        -------- Removing P so we remove leaks --------
        Custom script:   call RemoveLocation (udg_P)
        -------- Setting P (Point Variable) to center so we move them there --------
        Set P = (Center of (Playable map area))
        -------- Usefull little custom script for faster remove of group leak, making them destroy automatically --------
        Custom script:   set bj_wantDestroyGroup = true
        -------- Picking one random unit from player red (can be easyly edited to be any player but its more fun for it to be choosen player :D) --------
        Unit Group - Pick every unit in (Random 1 units from (Units owned by Player 1 (Red))) and do (Actions)
            Loop - Actions
                -------- Ordering unit to move --------
                Unit - Order (Picked unit) to Move To P
                -------- Some extra Integer fun: setting it to random number so we get different colored unit every time --------
                Set I = (Random integer number between 1 and 4)
                -------- Coloring the unit to one color from 4 randomly --------
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        I Equal to 1
                    Then - Actions
                        Unit - Change color of (Last created unit) to Purple
                    Else - Actions
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                I Equal to 2
                            Then - Actions
                                Unit - Change color of (Last created unit) to Black
                            Else - Actions
                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    If - Conditions
                                        I Equal to 3
                                    Then - Actions
                                        Unit - Change color of (Last created unit) to Green
                                    Else - Actions
                                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                            If - Conditions
                                                I Equal to 4
                                            Then - Actions
                                                Unit - Change color of (Last created unit) to Blue
                                            Else - Actions
        -------- Removing P so we remove leaks --------
        Custom script:   call RemoveLocation (udg_P)

I edited my code a little so it is more fun.
I coulod easyly make it be strictly random unit from all units and blue color :D.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
My solution to the assignment. Basically picks a random unit from all player and gives the random unit to a random player and teleports it to a random point. Wow, so much random.

Code:
Random Coloured Unit
    Events
        Time - Every 5.00 seconds of game time
    Conditions
    Actions
        -------- I'm too lazy to comment further, the actions are quite self-explanatory. ;-) (Atleast made this comment, right?) --------
        Player Group - Pick every player in (All players) and do (Actions)
            Loop - Actions
                Set tmpGroup = (Units owned by (Picked player))
                Set tmpUnit = (Random unit from tmpGroup)
                Custom script:   call DestroyGroup( udg_tmpGroup )
                Unit - Change ownership of tmpUnit to (Player((Random integer number between 1 and 16))) and Change color
                Set tmpPoint = (Random point in (Playable map area))
                Cinematic - Ping minimap for (All players) at tmpPoint for 1.00 seconds
                Unit - Move tmpUnit instantly to tmpPoint
                Custom script:   call RemoveLocation( udg_tmpPoint )
 
I

IKilledKEnny

Guest
Bonus trigger:

Code:
Set Change Owner
    Events
        Map initialization
    Conditions
    Actions
        -------- TempF = Nulled Player Group --------
        -------- Sets TempF to all players that are named "Tonks" --------
        Set TempF = (All players matching ((Name of (Matching player)) Equal to Tonks))
        Player Group - Pick every player in TempF and do (Actions)
            Loop - Actions
                -------- We add to "Change Owner" trigger the event - Picked player types "I love blue"  --------
                Trigger - Add to Change Owner <gen> the event (Player - (Picked player) types a chat message containing I love blue as An exact match)
        -------- In order to avoid leaks, we remove TempF from the computer's memory --------
        Custom script:   call DestroyForce(udg_TempF)
        -------- This trigger will result that whenever a player named Tonks type "I love blue" --------
        -------- "Change Owner" trigger will run - This trigger is nothing but a bonus. --------

Real Trigger:

Code:
Change Owner
    Events
    Conditions
    Actions
        -------- TempG = Nulled unit group --------
        -------- TempP = Nulled location --------
        -------- TempU = Nulled unit --------
        -------- Setting TempG to all units --------
        Set TempG = (Units in (Playable map area))
        -------- Getting a random unit from TempG and changing it's owner to blue --------
        Set TempU = (Random unit from TempG)
        Unit - Change ownership of (Random unit from TempG) to Player 2 (Blue) and Change color
        -------- We remove the unit group to avoid leaks --------
        Custom script:   call RemoveGroup(udg_TempG)
        -------- We move the unit to the middle of the map --------
        Set TempP = (Center of (Playable map area))
        Unit - Move TempU instantly to TempP
        -------- And we finally remove the location --------
        Custom script:   call RemoveLocation(udg_TempP)
 

Sooda

Diversity enchants
Reaction score
318
I suggest to start using informative variable names. I have done that fault myself naming variables a, b, c, d, e, h, ... and so on. When you after some time look your code (Or somebody else) it is very hard and time consuming to understand it again.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Meh, making comments for such a simple trigger, especially, for every action, is quite absurd. It's like reading a single row of code, twice.:p
 

Tonks

New Member
Reaction score
160
- Gone until Monday the 23rd -

I will not be able to view the thread until then.

We don't need to clear Unit variables, do we? Or do you mean to say that I should not name my variables with "temp" in front unless they are specifically for the cleaning up leaks?

No. The Comment functions inserts comments directly into the trigger, which can be moved around as other functions can. The header above the trigger is not actually part of the trigger.

So the trigger header is just another place for comments, right? It does the same thing, just in a different place.

One more quick question regarding the Custom Script: Do the spaces matter?
Code:
Custom script:   call DestroyGroup(udg_tempUnitGroup)
Custom script:   call DestroyGroup (udg_tempUnitGroup)
Custom script:   call DestroyGroup( udg_tempUnitGroup)
Custom script:   call DestroyGroup ( udg_tempUnitGroup)
All the same?

No, you don't need to clear unit variables. I was just testing your knowledge.

Yes, trigger heading is just a comments area. I sometimes use it to make notes.

I don't think that the spaces matter in that case, but I'm not entirely positive. I'm not particularly Jass-savvy.
Could someone who knows about Jass please confirm / correct that statement?

I couldn't find any explanation about forces leaks, which are actually even worse then location leaks.

I will add my assignment (as an example more then anything else...) as soon as I get to a computer with WE.

I don't believe forces leak, as they aren't assigned as integers.

Meh, making comments for such a simple trigger, especially, for every action, is quite absurd. It's like reading a single row of code, twice.

Yes, I agree that it is a bit of overkill for this assignment. However, in later lessons, it will become more of a necessity.


I will grade the other assignments when I get back.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
I suggest to start using informative variable names. I have done that fault myself naming variables a, b, c, d, e, h, ... and so on. When you after some time look your code (Or somebody else) it is very hard and time consuming to understand it again.

That is informative... If you didn't notice, his globals were:
- TempF
- TempG
- TempU
- TempP
-- TempF = TempForce
-- TempG = TempGroup
-- TempU = TempUnit
-- TempP = TempPoint

It isn't very hard to interpret as long as you have at least some knowledge of TE.

Here is mine... Simply picks a random unit and changes his color. c'n'p from my trigger. Then it makes the unit get issued to a region center.
Code:
Blue Colored Unit
    Events
        Player - Player 1 (Red) types a chat message containing -BeBlue as An exact match
    Conditions
    Actions
        -------- Registers the typing event so that the trigger fires when the text is entered --------
        Player Group - Pick every player in (All players) and do (Actions)
            Loop - Actions
                -------- Picks every player and creates a loop --------
                Set tempgroup = (Units owned by (Picked player))
                -------- Sets tempgroup as every unit owned by the picked player which is (All Players) --------
                Set tempunit = (Random unit from tempgroup)
                -------- Sets tempunit as a random unit from tempgroup --------
                Set temppoint = (Center of My Big Fat Region 000 <gen>)
                -------- Sets temppoint as the center of "My Big Fat Region" --------
                Unit - Change color of tempunit to Blue
                -------- Changes the color of the random unit (tempunit) to blue --------
                Unit - Move tempunit instantly to temppoint
                -------- Moves the color changed unit to temppoint --------
                Custom script: call RemoveLocation(udg_temppoint)
                -------- Removes the location (udg_temppoint), thus preventing a point leak --------
                Custom script: call DestroyGroup(udg_tempgroup)
                -------- Destroys the group (udg_tempgroup), thus preventing a group leak --------

Enjoy! :D
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top