• 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] Combining element

Status
Not open for further replies.

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
hi,
is there a way to combine in the same line
create item for unit and set charge in created item.?
or even better create unit and add item in same line + charge if possible ?
[Jass=]
call CreateUnitAtLoc( Player(PLAYER_NEUTRAL_AGGRESSIVE), 'u001', udg_Loc, bj_UNIT_FACING )
call UnitAddItemById( GetLastCreatedUnit(), 'I0AG' )
call SetItemCharges( GetLastCreatedItem(), GetRandomInt(1, 5) )
[/code]

for example:
[Jass=]
call UnitAddItemById( CreateUnitAtLoc( Player(PLAYER_NEUTRAL_AGGRESSIVE), 'u001', udg_Loc, bj_UNIT_FACING ), 'I0AG' )
[/code]
is this ok?

[Jass=]
call SetItemCharges( UnitAddItemById( CreateUnitAtLoc( Player(PLAYER_NEUTRAL_AGGRESSIVE), 'u001', udg_Loc, bj_UNIT_FACING ), 'I0AG' ), GetRandomInt(1, 5) )
[/code]
what about this?
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
the last one should work(it compiled at least)
be aware that GetLastCreatedItem and GetLastCreatedUnit will return null in your case, those are useful only when you are working with BJ versions of those function calls, you have to set variable to that, example:
JASS:
    local unit u = CreateUnit(...)
    local item i = UnitAddItemById(u, ...)
    call SetItemCharges(i, GetRandomInt(1, 5))

etc
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
hum i see...

but if i add them all together would it work even without using variable?
by replacing variable by function call, like the last one?

i will try it in a test map to see what happen

EDIT
Well it work perfectly fine... ^^
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
yes it will work, as long as the function returns the type you want it will work and thats because CreateUnit returns a unit that was created so you can manipulate with it either by placing it to variable or by using it in function
 
Status
Not open for further replies.
Top