- Joined
- Oct 24, 2012
- Messages
- 6,545
How to easily convert GUI into efficient JASS
Table of Contents
- Step 1 - Creating a GUI trigger
- Step 2 - Converting the GUI trigger
- Step 3 - How to understand the Syntax
- Step 4 - Understanding what happened to the Events
- Step 5 - Understanding what happened to the Conditions
- Step 6 - Understanding what happened to the Actions
- Step 7 - Starting on making the Events efficient
- Step 8 - Starting on making the Conditions efficient
- Step 9 - Starting on making the Actions efficient
- Finished Product
There are things out there to help you with functions. I use TESH, it is in JNGP.
What TESH does is it has a list of all of the function names, their arguments and what they return.
This is incredible valuable when writing JASS. It helps with the syntax of functions.
Step 1 - Creating a GUI trigger
Ok I have taken the liberty to create a GUI trigger as I believe you already know how to make GUI triggers.
Let me note that I have made this trigger not based on efficiency.
I have made this trigger to help show you the most things I can in one trigger to help you in converting later.
I made a pre-placed unit and a pre-placed Region( regions in GUI are called rects in JASS).
I added the pre-placed unit and region to help you understand how they work in JASS.
-
Step 1
-
Events
- Unit - A unit Dies
-
Conditions
- (Triggering unit) Equal to Footman 0000 <gen>
-
Actions
- Set tempPoint = (Random point in myRegion <gen>)
-
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-
If - Conditions
- (Life of (Triggering unit)) Greater than or equal to 10.00
-
Then - Actions
- Unit - Order (Triggering unit) to Move To tempPoint
-
Else - Actions
- Unit - Create 1 Footman for Player 1 (Red) at tempPoint facing 270.00 degrees
-
If - Conditions
- Custom script: call RemoveLocation( udg_tempPoint)
-
Events
Step 2 - Converting the GUI trigger
Now lets convert the Trigger.
This is very easy just click on the Edit button in the Trigger Editor.
Next click the Convert to Custom Text button and you're trigger should now look like this.
This May look like a garbled mess right now but don’t worry it's a lot easier than it looks like.
Take note everything that has call before it in here is a function call. Function calls are how you do everything in JASS.
GUI actions are converted into function calls when the map is compiled(saved).
JASS:
function Trig_Step_1_Conditions takes nothing returns boolean
if ( not ( GetTriggerUnit() == gg_unit_hfoo_0000 ) ) then
return false
endif
return true
endfunction
function Trig_Step_1_Func002C takes nothing returns boolean
if ( not ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) >= 10 ) ) then
return false
endif
return true
endfunction
function Trig_Step_1_Actions takes nothing returns nothing
set udg_tempPoint = GetRandomLocInRect(gg_rct_myRegion)
if ( Trig_Step_1_Func002C() ) then
call IssuePointOrderLocBJ( GetTriggerUnit(), "move", udg_tempPoint )
else
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), udg_tempPoint, 270.00 ) // notice player(0). in JASS player 1 red is actually Player(0)
endif
call RemoveLocation( udg_tempPoint)
endfunction
//===========================================================================
function InitTrig_Step_1 takes nothing returns nothing
set gg_trg_Step_1 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Step_1, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_Step_1, Condition( function Trig_Step_1_Conditions ) )
call TriggerAddAction( gg_trg_Step_1, function Trig_Step_1_Actions )
endfunction
Step 3 - How to understand the Syntax
First let me explain how to declare and read a function.
JASS:
function Name takes Arguments returns argument
Were I have "Name" that is were you declare what the function is called.
Then you put the takes keyword this is to declare the start of the arguments that function will take.
Were I have "Arguments" you need to replace that with the arguments.
Arguments are What the function takes.
To simplify this the arguments in
- Unit - Order (Triggering unit) to Move To tempPoint
For example if you want your function to take an integer you right it like this.
JASS:
function Name takes integer I returns argument
The I is the integer name. This is important. I will show you examples of why it is important soon.
If you want your function to take multiple arguments you added a comma after the I. Then you need to put the type of variable and then the name of that variable.
Next you need the return keyword. This declares what you are returning.
You return a variable or nothing. Lets take the creation of a group. This returns a group.
Finally you need to declare what to return. This is how you do that.
JASS:
function Name takes nothing returns real
This is how you use that.
JASS:
function Name takes unit u returns real
return GetUnitState( u, UNIT_STATE_LIFE)
endfunction
In this example I am taking a unit argument and returning its life.
Functions are very useful for when you have to repeat actions cause you can store those repeated actions in the function and call the function when you need to. It will then store the data you want and/or return a value.
As a last note. When you create a function you need to end it. To do this you need the endfunction keyword at the end of your function.
Step 4 - Understanding what happened to the Events
JASS:
function InitTrig_Step_1 takes nothing returns nothing
set gg_trg_Step_1 = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Step_1, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( gg_trg_Step_1, Condition( function Trig_Step_1_Conditions ) )
call TriggerAddAction( gg_trg_Step_1, function Trig_Step_1_Actions )
endfunction
Now easy way to look at it is look at the line that says call TriggerRegisterAnyUnitEventBJ( gg_trg_Step_1, EVENT_PLAYER_UNIT_DEATH )
This is the Event. It is changed into this when converted. There are many different type of events so they don’t always look like this.
If you look closely all Events have the words TriggerRegister and Event in them. That’s how you can easily tell which calls are Events.
TriggerRegister is how you register events to triggers.
TriggerAddAction is how you add Action functions to the trigger.
TriggerAddCondition is how you add Condition functions to the trigger.
Step 5 - Understanding what happened to the Conditions
There are 2 types of conditions that I have placed in here.
First one is the Condition in the condition block(the one right under the Events in GUI).
Second is the Condition in the ITE(if then else) block.
These are slightly different in JASS but only because of how you deal with them.
Conditions always have function name takes nothing returns boolean
The boolean is a true or false for the condition.
JASS:
//this is the first condition. The one in the condition block under the events block.
call TriggerAddCondition( gg_trg_Step_1, Condition( function Trig_Step_1_Conditions ) )
//You may be asking what happened to the condition I made. It looks confusing.
//Look at the inside of the function call. Specifically this ( Condition( function Trig_Step_1_Conditions ))
//This is your condition converted in JASS. It translates it into another function call because it needs to return a boolean.
//So to find the condition look for function Trig_Step_1_Conditions
//Here it is and note the returns boolean at the end of the function line.
function Trig_Step_1_Conditions takes nothing returns boolean
if ( not ( GetTriggerUnit() == gg_unit_hfoo_0000 ) ) then
return false
endif
return true
endfunction
//I will be explaining how to improve these later. I think its easier to show what is what, then to show how to improve it step by step.
//Here is the second condition. The one in the ITE block.
//First you have to locate the ITE. Here it is.
if ( Trig_Step_1_Func002C() ) then
call IssuePointOrderLocBJ( GetTriggerUnit(), "move", udg_tempPoint )
else
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), udg_tempPoint, 270.00 )
endif
//Notice the if portion. It says
if ( Trig_Step_1_Func002C() ) then
//Just like before it translates into a function call. The reason it doesn't have call Trig_Step_1_Func002C() is because the if is basically a call.
//So you do not need to call twice.
//now lets locate function Trig_Step_1_Func002C()
//Here it is
function Trig_Step_1_Func002C takes nothing returns boolean
if ( not ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) >= 10 ) ) then
return false
endif
return true
endfunction
//Now you should know how to tell the conditions from the functions.
Step 6 - Understanding what happened to the Actions
As I have said above function calls are actions.
JASS:
if ( Trig_Step_1_Func002C() ) then
call IssuePointOrderLocBJ( GetTriggerUnit(), "move", udg_tempPoint )
else
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), udg_tempPoint, 270.00 )
endif
//Notice the IssuePointOrderLocBJ and CreateNUnitsAtLoc.
//These are the actions
Step 7 - Starting on making the Events efficient
I’m going to explain how to fix this by starting with the event function and making it efficient.
Lets take a look at the events function again.
JASS:
function InitTrig_Step_1 takes nothing returns nothing
set gg_trg_Step_1 = CreateTrigger( ) // The gg_trg_Step_1 is the trigger.
call TriggerRegisterAnyUnitEventBJ( gg_trg_Step_1, EVENT_PLAYER_UNIT_DEATH ) // This is the event as said before.
call TriggerAddCondition( gg_trg_Step_1, Condition( function Trig_Step_1_Conditions)) // this is how the conditions are added to the trigger.
call TriggerAddAction( gg_trg_Step_1, function Trig_Step_1_Actions) // this is how the actions are added to the trigger.
endfunction
First take a look at the notes I placed in the trigger function.
I showed you what each line means.
Next ill show you how to make these efficient.
Ill start off with the first line. set gg_trg_Step_1 = CreateTrigger()
To make the trigger more efficient we will use a local variable. A local variable is a variable that is only used in that function.
It's better to keep local variable names shorter. You can use one letter for these most of the time.
Also whenever you change the trigger with a local or global variable you need to change it in the other function calls it is used in.
In this case it is used in the call TriggerRegisterAnyUnitEventBJ, call TriggerAddCondition, call TriggerAddAction
The reason I know it's used in these is the arguments it takes.
You can find out what arguments it takes if you hit CTRL and click on TriggerRegisterAnyUnitEventBJ.
This will show you this.
JASS:
function TriggerRegisterAnyUnitEventBJ takes trigger trig, playerunitevent whichEvent returns nothing
local integer index
set index = 0
loop
call TriggerRegisterPlayerUnitEvent(trig, Player(index), whichEvent, null)
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
endfunction
Note the takes trigger. This is an argument. So you need to plug in a trigger there. The current trigger is gg_trg_Step_1.
So when we change the current trigger we need to change the trigger arguments.
Here is the new function with the trigger changed to a local variable.
JASS:
function InitTrig_Step_1 takes nothing returns nothing
local trigger t = CreateTrigger( ) // for a local variable you have to type local .type of variable. and the name
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH ) // note the trigger variable is changed
call TriggerAddCondition( t, Condition( function Trig_Step_1_Conditions)) // note the trigger variable is changed
call TriggerAddAction( t, function Trig_Step_1_Actions) // note the trigger variable is changed
set t = null // note this. this is like the custom scripts you use to null variables in GUI. You have to null them here also.
endfunction
Next step - lets check out the event. TriggerRegisterAnyUnitEventBJ
This is one of the few BJs that is ok to use. The others you will want to look up the native function and use that native function instead.
I will show you more on native functions in the next couple of steps.
JASS:
function Trig_Step_1_Conditions takes nothing returns boolean
if ( not ( GetTriggerUnit() == gg_unit_hfoo_0000 ) ) then
return false
endif
return true
endfunction
function Trig_Step_1_Func002C takes nothing returns boolean
if ( not ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) >= 10 ) ) then
return false
endif
return true
endfunction
function Trig_Step_1_Actions takes nothing returns nothing
set udg_tempPoint = GetRandomLocInRect(gg_rct_myRegion)
if ( Trig_Step_1_Func002C() ) then
call IssuePointOrderLocBJ( GetTriggerUnit(), "move", udg_tempPoint )
else
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), udg_tempPoint, 270.00 )
endif
call RemoveLocation( udg_tempPoint)
endfunction
//===========================================================================
function InitTrig_Step_1 takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( t, Condition( function Trig_Step_1_Conditions))
call TriggerAddAction( t, function Trig_Step_1_Actions)
set t = null
endfunction
Step 8 - Starting on making the Conditions efficient
Now this one I will show you how to make Conditions efficient since GUI does a very noticeably bad job at this.
First take a look at the condition function for the trigger.
JASS:
function Trig_Step_1_Conditions takes nothing returns boolean
if ( not ( GetTriggerUnit() == gg_unit_hfoo_0000 ) ) then // note the gg_unit_hfoo_0000. This is a pre-placed unit.
return false
endif
return true
endfunction
Notice the return false and return true. These are the booleans that get returned.
Also they use an ITE in there. The ITE is why this is inefficient. This can be simplified to return only what you want it to.
What I mean by that is we want to check if the triggering unit is the pre-placed unit.
To do this we can simplify it to return the trigger unit
Here is how we do this.
JASS:
function Trig_Step_1_Conditions takes nothing returns boolean
return GetTriggerUnit() == gg_unit_hfoo_0000 // Now you can see we return the unit.
endfunction
If you want to check if the triggering unit is not the pre-placed unit you do it like this.
JASS:
function Trig_Step_1_Conditions takes nothing returns boolean
return not GetTriggerUnit() == gg_unit_hfoo_0000 // notice the not in there. This checks to see if the triggering unit is not the pre-placed unit.
endfunction
Here is how this way works.
This GetTriggerUnit() == gg_unit_hfoo_0000 returns a true or false.
So if the triggering unit is the pre-placed unit it returns true. If the triggering unit isn't the pre-placed unit it returns false.
Next lets take care of the condition in the ITE. This will be done slightly different. We do not need the function call for the ITE.
JASS:
function Trig_Step_1_Func002C takes nothing returns boolean
if ( not ( GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) >= 10 ) ) then
return false
endif
return true
endfunction
function Trig_Step_1_Actions takes nothing returns nothing
set udg_tempPoint = GetRandomLocInRect(gg_rct_myRegion)
if ( Trig_Step_1_Func002C() ) then
call IssuePointOrderLocBJ( GetTriggerUnit(), "move", udg_tempPoint )
else
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), udg_tempPoint, 270.00 )
endif
call RemoveLocation( udg_tempPoint)
endfunction
Here is how we should change this. since the ITE can check the units life we will put that in there.
Notice the if has the condition you wanted to check right in it.
The function is now not needed.
JASS:
function Trig_Step_1_Actions takes nothing returns nothing
set udg_tempPoint = GetRandomLocInRect(gg_rct_myRegion)
if GetUnitStateSwap(UNIT_STATE_LIFE, GetTriggerUnit()) >= 10 ) then
call IssuePointOrderLocBJ( GetTriggerUnit(), "move", udg_tempPoint )
else
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), udg_tempPoint, 270.00 )
endif
call RemoveLocation( udg_tempPoint)
endfunction
This is still not as efficient as it can be. So lets change that.
First hold CTRL and click on GetUnitStateSwap you should see this.
JASS:
function GetUnitStateSwap takes unitstate whichState, unit whichUnit returns real
return GetUnitState(whichUnit, whichState) // note the names of the arguments and match them w the names of the variables for the arguments that the function call takes.
endfunction
It returns the native GetUnitState. So lets change this.
JASS:
function Trig_Step_1_Actions takes nothing returns nothing
set udg_tempPoint = GetRandomLocInRect(gg_rct_myRegion)
if GetUnitState( GetTriggerUnit(), UNIT_STATE_LIFE) >= 10 ) then // now it checks if the units life is greater than or equal to 10 using the native function call
call IssuePointOrderLocBJ( GetTriggerUnit(), "move", udg_tempPoint )
else
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), udg_tempPoint, 270.00 )
endif
call RemoveLocation( udg_tempPoint)
endfunction
Now the conditions are improved for efficiency.
JASS:
function Trig_Step_1_Conditions takes nothing returns boolean
return GetTriggerUnit() == gg_unit_hfoo_0000
endfunction
function Trig_Step_1_Actions takes nothing returns nothing
set udg_tempPoint = GetRandomLocInRect(gg_rct_myRegion)
if GetUnitState( GetTriggerUnit(), UNIT_STATE_LIFE) >= 10 ) then
call IssuePointOrderLocBJ( GetTriggerUnit(), "move", udg_tempPoint )
else
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), udg_tempPoint, 270.00 )
endif
call RemoveLocation( udg_tempPoint)
endfunction
//===========================================================================
function InitTrig_Step_1 takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( t, Condition( function Trig_Step_1_Conditions))
call TriggerAddAction( t, function Trig_Step_1_Actions)
set t = null
endfunction
Step 9 - Starting on making the Actions efficient
Now we can work on the actions.
JASS:
function Trig_Step_1_Actions takes nothing returns nothing
set udg_tempPoint = GetRandomLocInRect(gg_rct_myRegion)
if GetUnitState( GetTriggerUnit(), UNIT_STATE_LIFE) >= 10 ) then
call IssuePointOrderLocBJ( GetTriggerUnit(), "move", udg_tempPoint )
else
call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), udg_tempPoint, 270.00 )
endif
call RemoveLocation( udg_tempPoint)
endfunction
Not you should make a global region variable. I called mine region. in JASS this is written udg_region.
Now in a map init trigger set your variable to the pre-placed rect.
The reason to do this is efficiency. It is faster to get a variable than to get a pre-placed region.
You may ask when should I put something into a variable. Whenever you use it twice or more is what i go by.
- Set region = myRegion <gen>
Then you create local variables a local real x and a local real y and then you get the random reals.
To find out how to assign the random reals.
Hold CTRL and click on the GetRandomLocInRect and this will show you what to do.
JASS:
local real x = GetRandomReal(GetRectMinX( udg_region), GetRectMaxX( udg_region))
local real y = GetRandomReal(GetRectMinY( udg_region), GetRectMaxY( udg_region))
Second lets change the IssuePointOrderLocBJ
If you hold CTRL and click on this one you still have the location.
But if you look in the functions list you can find this action.
JASS:
native IssuePointOrder takes unit whichUnit, string order, real x, real y returns boolean
This is a safer point order to use since it uses reals which don't leak.
To use this you put in the unit, the order string, and then the local reals x and y
JASS:
call IssuePointOrder( GetTriggerUnit(), "move", x, y)
Finally lets do the CreateNUnitsAtLoc
This one also has a safer function call. Here it is.
JASS:
native CreateUnit takes player id, integer unitid, real x, real y, real face returns unit
To use this you put in the player id, unitID, and then the local reals x and y, and the face.
First like i said before player 1 red in GUI is Player(0) in JASS.
Second the unit Id can be found by going to the object editor and click View -> Display Values as Raw Data.
Then look for the units data you want. ex 'hpea' is a peasant. 'hfoo' is a footman
The Raw values are integers. More specifically they are ASCII integers.
The face value is the direction they face in.
JASS:
call CreateUnit( Player(0), 'hfoo', x, y, 270)
Also lets add in a local unit u = GetTriggerUnit()
As per the rule I stated before whenever something is called two or more times put it in a variable.
We also need to null this at the end of the function.
Note: when you have a return make sure to null all values before the return.
The reason for this is return is the same as skip remaining actions in GUI.
It will end the function so everything after that doesn’t happen.
If you don't null the variables before it, you will leak.
Finished Product
Finally you can get rid of the useless point variables.
Now for the last thing you should never use TriggerAddAction(). Here is why.
So we need to get rid of the trigger add actions and transfer everything to use trigger add condition.Ask them to merge the conditions and actions and use conditions rather than action for triggers.
Actions creates new thread, conditions don't.
First we will change this line.
JASS:
function InitTrig_Step_1 takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( t, Condition( function Trig_Step_1_Conditions))
call TriggerAddAction( t, function Trig_Step_1_Actions)
set t = null
endfunction
//change it to this. I only got rid of the TriggerAddAction()
function InitTrig_Step_1 takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( t, Condition( function Trig_Step_1_Actions)) // also changed this
set t = null
endfunction
//next change this
function Trig_Step_1_Conditions takes nothing returns boolean
return GetTriggerUnit() == gg_unit_hfoo_0000
endfunction
function Trig_Step_1_Actions takes nothing returns boolean
local real x = GetRandomReal(GetRectMinX( udg_region), GetRectMaxX( udg_region))
local real y = GetRandomReal(GetRectMinY( udg_region), GetRectMaxY( udg_region))
if GetUnitState( GetTriggerUnit(), UNIT_STATE_LIFE) >= 10 ) then
call IssuePointOrder( GetTriggerUnit(), "move", x, y)
else
call CreateUnit( Player(0), 'hfoo', x, y, 270)
endif
endfunction
//we need to change this into an ITE and get rid of the old condition function.
//Also move change the local variables and set them in the ITE.
//The reason for this is to only set the local variables when the condition is true.
//This keeps it efficient.
//Change it to this.
function Trig_Step_1_Actions takes nothing returns boolean
local real x
local real y
if GetTriggerUnit() == gg_unit_hfoo_0000 then
set x = GetRandomReal(GetRectMinX( udg_region), GetRectMaxX( udg_region))
set y = GetRandomReal(GetRectMinY( udg_region), GetRectMaxY( udg_region))
if GetUnitState( GetTriggerUnit(), UNIT_STATE_LIFE) >= 10 ) then
call IssuePointOrder( GetTriggerUnit(), "move", x, y)
else
call CreateUnit( Player(0), 'hfoo', x, y, 270)
endif
endif
return false
endfunction
JASS:
function InitTrig_Step_1 takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( t, Condition( function Trig_Step_1_Conditions))
call TriggerAddAction( t, function Trig_Step_1_Actions)
set t = null
endfunction
//change it to this. I only got rid of the TriggerAddAction()
function InitTrig_Step_1 takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( t, Condition( function Trig_Step_1_Conditions))
set t = null
endfunction
//next change this
function Trig_Step_1_Conditions takes nothing returns boolean
return GetTriggerUnit() == gg_unit_hfoo_0000
endfunction
//we need to change this back to an ITE.
//The reason I changed it before was to show you how you can return values if you need to.
//Change it to this.
function Trig_Step_1_Conditions takes nothing returns boolean
if GetTriggerUnit() == gg_unit_hfoo_0000 then
call Trig_Step_1_Actions() // this is how you call a function you have made.
endif
return false
endfunction
JASS:
function Trig_Step_1_Actions takes nothing returns boolean
local real x
local real y
local unit u = GetTriggerUnit()
if u == gg_unit_hfoo_0000 then
set x = GetRandomReal(GetRectMinX( udg_region), GetRectMaxX( udg_region))
set y = GetRandomReal(GetRectMinY( udg_region), GetRectMaxY( udg_region))
if GetUnitState( u, UNIT_STATE_LIFE) >= 10 then
call IssuePointOrder( u, "move", x, y)
else
call CreateUnit( Player(0), 'hfoo', x, y, 270)
endif
endif
set u = null
return false
endfunction
//===========================================================================
function InitTrig_Step_1 takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( t, Condition( function Trig_Step_1_Actions))
set t = null
endfunction
Here is another way you could structure this. You can decide which one you like more.
In this one you have to switch the condition function under the actions function.
Two reasons I do this.
1) You technically have to. JASS reads things from bottom up.
In other words if you put conditions function on top it cannot call the actions function.
2) If you always keep your condition functions at the bottom its always easy to find them.
JASS:
function Trig_Step_1_Actions takes nothing returns nothing
local real x = GetRandomReal(GetRectMinX( udg_region), GetRectMaxX( udg_region))
local real y = GetRandomReal(GetRectMinY( udg_region), GetRectMaxY( udg_region))
local unit u = GetTriggerUnit()
if GetUnitState( u, UNIT_STATE_LIFE) >= 10 then
call IssuePointOrder( u, "move", x, y)
else
call CreateUnit( Player(0), 'hfoo', x, y, 270)
endif
set u = null
endfunction
function Trig_Step_1_Conditions takes nothing returns boolean
if GetTriggerUnit() == gg_unit_hfoo_0000 then
call Trig_Step_1_Actions() // this is how you call a function you have made.
endif
return false
endfunction
//===========================================================================
function InitTrig_Step_1 takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_DEATH )
call TriggerAddCondition( t, Condition( function Trig_Step_1_Conditions))
set t = null
endfunction
For better understanding on how functions are read / used / implemented you should look at this tutorial. http://www.hiveworkshop.com/forums/jass-ai-scripts-tutorials-280/jass-what-func-238298/
If you have any more questions please feel free to ask on here or pm me.
Last edited: