Tyman2007
Ya Rly >.
- Reaction score
- 74
Jass Unit Revive Trigger (A Jass Tutorial)
This tutorial teaches you jass by teaching you how to make a unit revive trigger.Remember, this is a Jass Tutorial. The Unit Revive Trigger is just something to teach you Jass by.
Some people like big blocks of text while others don't, which is why I will have a short explanation and a long explanation.
Don't feel worried that you HAVE to read the long explanations! The short explanations summarize it in 1 or 2 sentences, it is just for those people who want to know, "Why" or a little more about the answer.
I have to say, you will do better at jass when reading the long answers. If you've read this tutorial and just want to review each section quickly, the short answers can come in handy.
Index
1. Introduction
- a. Why use Jass?
- b. Why should you follow this tutorial?
- c. This has been posted a lot, why post it again.
2. Requirements and Recommendations
- a. What you should know.
- b. The programs.
- a. The trigger in GUI
- b. The trigger in Jass
- c. The first step in conversion
- d. Something to notice right away
- a. Locals and Globals
- b. What is a call?
- c. What is takes and returns on a function?
- d. Function arguments and you.
- e. What is a trigger?
- a. Adding locals
- b. Converting BJs to Natives
- c. Removing Leaks / Nullifying
1. Introduction
a. Why use Jass?
Short answer: Makes making this MUI a whole lot easier as well as cleaning up the script a little bit.a. Why use Jass?
Long answer: GUI is a very simplistic way of making your very own trigger. It is the starting point of any good triggerer and the only point for those who just give up. GUI is simple so it's better right? Wrong. GUI is simpler, but one thing you should know about GUI. GUI, though as unlikely as it seems, it SLOWER to make a trigger with than Jass. GUI generates Jass script methodically. Because of this, The trigger is very inefficient and slow. Jass is definately more flexible when it comes to reusing code. Jass also uses local variables which are much easier to create than a global because you just have to type in the simple line [ljass]local variable name = value[/ljass]. They are also much better because they are MUI over waits.
That seems like enough for 1.a
b. Why should you follow this tutorial?
Short Answer: Teaching you basic jass in a different way than others. You might not get it one way, but get it another way.Long Answer: I love helping people out, I love doing this kindof stuff, I love the helper. The question of why you should even bother with this tutorial remains with every tutorial out there. Is it because it's unique and no other tutorial's like it? (I don't know of a tutorial out there with short and long explanations). Is it BECAUSE it has long explanations? (Maybe). Is it mainly because you want someone Else's voice to show you the way and trying to cram in all that info and make it into something you would understand? All I can say is that you should look at each tutorial and take the things you learned and read another one to help you review what you learned from the previous tutorial and possibly learn something new. I can't fully answer this question, but I have a feeling that if I asked a couple people who liked this tutorial, every single one of them would have their own unique answer. (No they wouldn't, There's only one undefined reason)
putting it simple, everyone learns in different ways, and one could be simpler than another to you.
c. This has been posted a lot, why post it again?
I can't really give a short and long answer for this one. You should read the above one. I can give a short answer.To teach you in a different way.
2. Requirements and Recommendations
a. What you should know
Short Answer: You should AT LEAST know how to make a trigger enhanced spell in GUI for you learn a couple of jass functions.
Long Answer: There are a couple things at which you should already know by reading this tutorial. The first thing which is more of a recommendation than a requirement, is the knowledge on how to make a trigger enhanced spell. Why? Because why would you want to use the efficiency of jass if you don't know if you'll be satisfied with the efficiency of GUI? (Rhetorical Question). GUI Also teaches you a few things about jass. Removing locations unit groups, and player groups. I did say a few, didn't I? (Again, Rhetorical Question). Aside from that, you don't really need to know anything else to learn how to write Jass.
b. Programs
Short Answer: World editor (with warcraft 3), and Highly recommended Jass Newgen (Link Below).Long Answer: The first required program goes without saying. You need world editor to start jass. If you don't have world editor on any of your computers or your friends computer, I highly suggest you walk away from this tutorial. Also a recommendation is Jass Newgen. This is a MUST for ANY jass user. This makes making jass script so much easier.
A download for Jass Newgen is here and can be discussed here.
3. Getting Started
a. The trigger in GUI
a. The trigger in GUI
Here's the revival trigger in GUI (Made simple for tutorial)
Trigger:
- ReviveGUI
- Events
- Unit - A unit Dies
- Conditions
- ((Dying unit) is A Hero) Equal to (==) False
- Actions
- Wait 10.00 seconds
- Unit - Create 1 (Unit-type of (Dying unit)) for (Owner of (Dying unit)) at (Position of (Dying unit)) facing (Facing of (Dying unit)) degrees
- Events
Long Answer: At first glance, this trigger leaks. I'm not trying to say anything bad about GUI, but in order to make this leakless, it requires a little more effort than Jass. This may be MUI, but as I said above, GUI is slower than jass. fixing the leak may take 10-20 seconds for a GUI user or 5-10 for a Jass user.
b. The trigger in Jass
Down below is an example of a perfectly working Jass revive trigger. I'm showing you what this looks like so you can get the basic idea of what a jass trigger looks like. I will explain about every function later. I'm just showing you what the trigger looks like. Try to make out what each thing is doing.JASS:
function Trig_ReviveJass_Conditions takes nothing returns boolean
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == false
endfunction
function Trig_ReviveJass_Actions takes nothing returns nothing
local real time = 10
local unit u = GetDyingUnit()
local location loc = GetUnitLoc(u)
call TriggerSleepAction( time )
call CreateUnitAtLoc( GetOwningPlayer(u), GetUnitTypeId(u), loc, GetUnitFacing(u))
call RemoveUnit(u)
call RemoveLocation(loc)
set u = null
endfunction
//===========================================================================
function InitTrig_ReviveJass takes nothing returns nothing
set gg_trg_ReviveJass = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_ReviveJass, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_ReviveJass, Condition( function Trig_ReviveJass_Conditions ) )
call TriggerAddAction( gg_trg_ReviveJass, function Trig_ReviveJass_Actions )
endfunction
Now the reason I'm not going to do any explaining on this yet is because it's just for reference.
c. The first step in conversion
Short Answer: Select the trigger you want to convert, click edit at the top, click convert to custom text.(Recommended you should read this long answer)
Long Answer: The first step for anyone to making a jass trigger is to create a basic trigger like the GUI one above and select that trigger. Next thing to do is click edit at the top and select convert to custom text. Now what that's going to do is take every GUI function that you put down and convert it into a Jass function. Most GUI functions are what we call BJs (Blizzard.j's). If you have Jass Newgen, they appear red. There are a few types of functions. The ones we should note right now are BJ's and natives. A BJ is a function made by blizzard that calls other function(s), and a native is a function hardcoded into the game engine. BJ's are only useless if they don't do anything useful. For the ones that are useless, Why have a function call just one function? Why not just call the function it calls? (You're calling someone saying, "Can you call this person and tell him hi?" when you have the guts to do so yourself and you know his number). we do our best to avoid those.
d. Something to notice right away
So, We have just converted our trigger and this is what we get.JASS:
function Trig_Revive_Jass_Conditions takes nothing returns boolean
if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == false ) ) then
return false
endif
return true
endfunction
function Trig_Revive_Jass_Actions takes nothing returns nothing
call TriggerSleepAction( 10.00 )
call CreateNUnitsAtLoc( 1, GetUnitTypeId(GetDyingUnit()), GetOwningPlayer(GetDyingUnit()), GetUnitLoc(GetDyingUnit()), GetUnitFacing(GetDyingUnit()) )
endfunction
//===========================================================================
function InitTrig_Revive_Jass takes nothing returns nothing
set gg_trg_Revive_Jass = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Revive_Jass, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_Revive_Jass, Condition( function Trig_Revive_Jass_Conditions ) )
call TriggerAddAction( gg_trg_Revive_Jass, function Trig_Revive_Jass_Actions )
endfunction
The first thing you should notice right off the bat is this.
JASS:
function Trig_Revive_Jass_Conditions takes nothing returns boolean
if ( not ( IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == false ) ) then
return false
endif
return true
endfunction
The first step we can do to edit this trigger is replace
JASS:
return true
with
JASS:
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == false
and delete everything above that up to function so it's just
JASS:
function Trig_Revive_Jass_Conditions takes nothing returns boolean
return IsUnitType(GetTriggerUnit(), UNIT_TYPE_HERO) == false
endfunction
Why?
Short Answer: We're making it check if it's true and we don't care if it's false, why do anything if it is.
Long Answer: At first glimpse, it looks weird. Why check if it's false instead of checking if it's true? Why even care if it's false. The game automatically can tell if it's false if it's not true anyway, so why not just return if it's true? I can't explain this part very well. It makes it look a whole lot neater is what it does. If anyone has a better explanation please post so and I will acknowledge you at the earliest convenience.
4. Explaining some things
a. Locals and Globals
a. Locals and Globals
Local variable types are case sensitive as well as the names!!!
EVERYTHING IN JASS IS CASE SENSITIVE!
IMPORTANT TO REMEMBER.
And please don't get variable names mixed up. Make them have a noticeable difference.
using v1, v2, v3, or v and V aren't very good choices.
Short Answer: Locals are variables for the specific function they're in while globals are for all functions (Identified using udg_ which stands for User Defined Global and are your only option in GUI).
Long Answer: Locals are variables that can only be used in Jass. Locals are specific to the function they are created in and MUST be at the top of the function they are in. So this won't work.
[lJASS]
local unit u[/ljass]
[lJASS]call KillUnit(u)[/ljass]
[lJASS]local integer i[/lJASS]
but this will
[lJASS]
local unit u[/ljass]
[lJASS]local integer i[/ljass]
[lJASS]call KillUnit(u)[/lJASS]
While globals are for EVERY trigger/function out there. You specify the arguments for each global (The type, the initial value, if it's an array) inside the variable editor for the game to create a global using those arguments. They generate the globals with the arguments and specify them using udg_VariableName (These are your only option as a GUI user). Locals can be defined using [ljass]local type name = value[/ljass] or as an array [ljass]local type array name[/ljass] (Notice the array cannot be initialized)
There are also things called "global blocks" which are used in vJass. There is still much more to jass than what I'm teaching you. globals inside the global blocks don't need udg_, they can be private for the scope (a scope is like a trigger) or public for all.
b. What is a call?
Short Answer: it's basically saying to a function "Get me this with that" or "Calling" it to do something with something else.Long Answer: There isn't much to "call" so this long answer will be fairly short. Calling a function using the function name and the things inside the parenthesis (called arguments) is basically like calling up your friend on the phone saying "Ok, I will give you 5 dollars, 20 cents, and a coupon. Can you go to the store and buy me some milk with those items?" That's the best example I can come up with.
c. What is takes and returns on a function?
What is that? Let's break it down into smaller pieces and explain it like that.
JASS:
function //States this is actually a function
Trig_Revive_Jass_Conditions //The name of the function
takes nothing //Meaning it takes no arguments so the function would be call Trig_Revive_JasS_Conditions()
returns boolean //meaning, its returning a boolean to you. A boolean is a true/false statement and it's telling you either true or false through the return. return boolean is just like saying "Here's (True/False)"
local unit u
we wouldn't say
KillUnit(u())
We'd say
KillUnit(u)
of course this would work since it's a function name returning a unit.
KillUnit(GetTriggerUnit())
I don't have much else to say on this.
d. Function arguments and you
Simple native functionFirst off, These are the arguments of a function
call FunctionName(a, b, c, d, e)
Look at the variable types for the arguments! It can save your life!
Short Answer: the "takes unit whichUnit" part is the argument. Specified by "call KillUnit(whichUnit)"
Long Answer: Arguments take a value, and if a variable is provided, the game will use the value the variable is holding. Any function that takes nothing (Takes no arguments) can be called just by using call FunctionName(). Functions that take unit u (u is just for reference to the one writing the script explaining what that spot's for) can be called by doing call FunctionName(u). People make their own functions and their own arguments and usually include what those arguments are and what to input for them.
e. What is a trigger?
This isn't really important to know, but can relieve some confusion you may have on what on earth a trigger is.There is no short/long answer to this. This is a completely optional part.
Let's scroll up a little to the triggers and notice this line
JASS:
set gg_trg_Revive_Jass = CreateTrigger( )
"I don't remember ever creating a variable called gg_trg_Revive_Jass, where did it come from?"
You created that as soon as you created the trigger.
!Triggers Are Variables!
You specify you want the game to make a trigger when you right click and click "Create Trigger", then the game is simply generating a variable specifically for that trigger and creating the trigger.
Judging by the text above, you can just do local trigger t = CreateTrigger() and replace all the "gg_trg_Revive_Jass"'s with t right? (Another Rhetorical Question)
Because I personally don't know much about triggers, I can't explain what they are in full detail.
5. Adding some lines
a. Adding Locals
We take our function and look at it.a. Adding Locals
JASS:
function Trig_Revive_Jass_Actions takes nothing returns nothing
call TriggerSleepAction( 10.00 )
call CreateNUnitsAtLoc( 1, GetUnitTypeId(GetDyingUnit()), GetOwningPlayer(GetDyingUnit()), GetUnitLoc(GetDyingUnit()), GetUnitFacing(GetDyingUnit()) )
endfunction
The function needs variables to eliminate leaks.
We can shorten a few things here by assigning [lJASS]GetDyingUnit()[/lJASS] to a variable.
At the middle we would write
[lJASS]local unit u = GetDyingUnit()[/lJASS]
.... Please .... If you find anything wrong somewhere at this point, please correct me
(Don't. Any mistakes I will make from hereon are on purpose so I'm not doing the writing for you. Try to notice these mistakes and look into your knowledge so far to try to correct these mistakes. P.S. Pay attention to the variable types for the arguments on the function!!!)
You will find the 10.00 in [lJASS]TriggerSleepAction(10.00)[/lJASS].
We want to make it so that we can change it right on the spot, so we would write at the top
[lJASS]local integer time = 10[/lJASS]
then write in [lJASS]TriggerSleepAction(time())[/lJASS] instead of [lJASS]TriggerSleepAction(10.00)[/lJASS]
finally the location of the unit.
[lJASS]local Location loc = GetunitLoc(U)[/lJASS]
then replace
[lJASS]GetUnitLoc(GetDyingUnit)[/lJASS]
with
[lJASS]Loc[/lJASS]
Then finally replace every
[ljass]GetDyingUnit()[/ljass] with U so we get.
JASS:
function Trig_Revive_Jass_Actions takes nothing returns nothing
local integer time = 10
local Location loc = GetunitLoc(U)
call TriggerSleepAction( time )
local unit u = GetDyingUnit()
call CreateNUnitsAtLoc( 1, GetUnitTypeId(U), GetOwningPlayer(U), Loc, GetUnitFacing(U) )
endfunction
b. Converting BJs into Natives
Here I have a native[lJASS]native CreateUnitAtLoc takes player id, integer unitid, location whichLocation, real face returns unit[/lJASS]
This is the native function to
[lJASS]CreateNUnitsAtLoc()[/lJASS]
We only want to create 1 unit so we use the native function instead of CreateNUnitsAtLoc.
Using a corrected version of the above trigger, we find what we need to fill in first.
[lJASS]CreateUnitAtLoc(player, unit, location, facing)[/lJASS]
which turns out to be
[lJASS]CreateUnitAtLoc(GetOwningPlayer(u), GetUnitTypeId(u), loc, GetUnitFacing(u)[/lJASS]
in order to find out the native function to the BJ, simply look inside of newgen's function list for the name of the BJ.
There isn't much into converting BJs into natives, and one thing is for certain.
Not all BJs need to be converted! Only the ones that are pointless and stupid and non-complex in any way/shape/or form.
c. Removing leaks / Nullifying
This is rather simple. Everyone who knows how to make a leakless trigger enhanced spell knows how to remove leaks in jass.RemoveLocation(u)
set loc = null
should be posted at the end of the function.
That's all I got.
6. Conclusion
Thank you thank you THANK YOU for making it this far.In this tutorial we learned about:
-Local and Global variables
-Functions
-The first step in converting
-BJs, natives
-calls
-And how to make a unit revive trigger
..
In jass!
About Me:
This tutorial took me 2 hours 15 minutes counting to write WITHOUT BREAKS.
I'm only 14 so it seems like it's all "Wow this person is a bit active in writing good stuff" or something along that lines, then gets to "He's starting to get a bit lazy". There were 2 drawbacks that I had when writing this tutorial.
1. The average attention span of a teenager is about an hour and a half. I surpassed that by over a half an hour. (My attention span is around 3-5 hours)
2. It's late and I'm tired and have been typing and thinking for the past 2 hours.
Credits:
-Me for writing every single bit of this.
-Thehelper helpers for helping me help you help me help us all
-Everyone that taught me Jass
-My computer for being nice enough and not crashing my internet browser while I wrote this.
-Any other imaginary thing goes here.
-------------------------------------- More thanks to:
-Darthfett for helping me correct a bunch of mistakes.
FAQ:
Nothin yet...
Final Notes:
-This is my very first tutorial on anything for thehelper and pretty much everything else. This is my very first one, so if it's not perfect, please don't criticize me too much.
Questions, Comments, Concerns, Constructive Criticisms?
(Anything rude will be ignored. Anything somewhat constructive criticism will be acknowledged)
Thank you again.
Changelog:
All times are PST
9/11/09 11:52pm - Initial Release of tutorial.
9/12/09 4:00pm- Made a bit of corrections.
9/11/09 11:52pm - Initial Release of tutorial.
9/12/09 4:00pm- Made a bit of corrections.