• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] How to use (take unit return unit) in functions

Status
Not open for further replies.
Level 2
Joined
Dec 14, 2012
Messages
20
Guys just little bit of help if some one could explain how it works.

lets say I spawn a unit AL30 in the start of my map then somebody dies and I would like now add ability to Al30 unit? or kill him or heal him so on

Lets say stupid example like this


JASS:
function SpawnUnit takes nothing returns unit// Don't know if this is right
local unit u=CreateUnit(whateverplayer,'Al30',2000,2000,0)
return // what must I add here?
endfunction 



function AddAbility takes unit u returns nothing
set UnitAddAbility(u,'die')
endfunction

I would like to know how do u tell the function where to get the Unit? and or does it take the unit from the function down or above it? any one that would explain it to me would help alot
 
makers suggestions is better but if u want u could do something like this.
but this way leaks i believe...
JASS:
function SpawnUnit takes nothing returns unit// Don't know if this is right
local unit u=CreateUnit(whateverplayer,'Al30',2000,2000,0)
// only time to use something other than what maker suggested is if u have 
//actions tht u want the unit to do after u create the unit and b4 u return it
return u // this is what u add.
endfunction
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
Create a global variable "myUnit" and store the unit there when spawning it. The SpawnUnit function does not need to return anything.
Then you can use the global variable to refer to your unit later.

JASS:
function SpawnUnit takes nothing returns nothing 
    set udg_myUnit = CreateUnit(whateverplayer,'Al30',2000,2000,0)
endfunction


function AddAbility takes unit u returns nothing
    set UnitAddAbility(udg_myUnit,'die')
endfunction

If you use vJass you can define the global variable in a globals-block instead of the variable editor. In this case:
JASS:
globals
    unit myUnit
endglobals

unction SpawnUnit takes nothing returns nothing 
    set myUnit = CreateUnit(whateverplayer,'Al30',2000,2000,0)
endfunction

function AddAbility takes unit u returns nothing
    set UnitAddAbility(myUnit,'die')
endfunction

Note: this isnt MUI

@Makers suggestion: your code is creating the unit and adding the ability at the same time, as far as i understood DTBA wants to add the ability at a later point in time.
 
Level 2
Joined
Dec 14, 2012
Messages
20
Create a global variable "myUnit" and store the unit there when spawning it. The SpawnUnit function does not need to return anything.
Then you can use the global variable to refer to your unit later.

JASS:
function SpawnUnit takes nothing returns nothing 
    set udg_myUnit = CreateUnit(whateverplayer,'Al30',2000,2000,0)
endfunction


function AddAbility takes unit u returns nothing
    set UnitAddAbility(udg_myUnit,'die')
endfunction

If you use vJass you can define the global variable in a globals-block instead of the variable editor. In this case:
JASS:
globals
    unit myUnit
endglobals

unction SpawnUnit takes nothing returns nothing 
    set myUnit = CreateUnit(whateverplayer,'Al30',2000,2000,0)
endfunction

function AddAbility takes unit u returns nothing
    set UnitAddAbility(myUnit,'die')
endfunction

Note: this isnt MUI

@Makers suggestion: your code is creating the unit and adding the ability at the same time, as far as i understood DTBA wants to add the ability at a later point in time.
Thank u now I know how it works and yes that what I want to do :D
 
Level 2
Joined
Dec 14, 2012
Messages
20
Thanks guys its working fine

but why if I add the ability via jass its not in your level thingy like u can't level it to level 2 3 4, and so on but it has level ?how do I make it levelble
 
Level 12
Joined
Feb 22, 2010
Messages
1,115
If you add ability with triggers you can't make it levelable like normal skills which sucks.
 
Level 14
Joined
Jun 27, 2008
Messages
1,325
SetUnitAbilityLevel

Thats NOT what he meant, he wanted the ability to be a hero-ability so he can level it in the skills menu. Ceday got the point.

Just follow Maker's suggestion and it will be faster

But makers suggestion does something completely different, it adds the ability right after the unit is created, not at a later point in time.
Tell me if i misunderstood the question ...
 
Level 2
Joined
Dec 14, 2012
Messages
20
on that same note how does DOTA LOD add ability to hero after they are pickd(buyed?) and make them level
 
Status
Not open for further replies.
Top