• 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] Weird problem

Status
Not open for further replies.
Level 23
Joined
Apr 16, 2012
Messages
4,041
I don't know, maybe I'm idiot or blind or what, but
JASS:
function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    call CreateNUnitsAtLoc( 1, 'hfoo', Player(0), GetUnitLoc(gg_unit_H000_0029), bj_UNIT_FACING )
    call UnitApplyTimedLife( GetLastCreatedUnit(), 'BTLF', 0.01)
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_002 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_002 = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Untitled_Trigger_002, 2.00 )
    call TriggerAddAction( gg_trg_Untitled_Trigger_002, function Trig_Untitled_Trigger_002_Actions )
endfunction
works properly, but
JASS:
function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
call CreateUnit(Player(0), 'hfoo', GetUnitX( gg_unit_H000_0029), GetUnitY(gg_unit_H000_0029), 0)
call UnitApplyTimedLife( GetLastCreatedUnit(), 'BTLF', 0.01)
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_002 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_002 = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Untitled_Trigger_002, 2.00 )
    call TriggerAddAction( gg_trg_Untitled_Trigger_002, function Trig_Untitled_Trigger_002_Actions )
endfunction
Kills unit placed as last on my (GUI) trigger placing units at map init.(the unit is modified Knight 'h005' )
Even
JASS:
DisplayTextToPlayer(Player(0),0,0,GetUnitName(GetLastCreatedUnit()))
returns the other unit, also if i Set this unit into local variable it still says it's the last created unit before this one.
The spawn trigger is
  • spawn
    • Events
      • Time - Elapsed game time is 0.00 seconds
    • Conditions
    • Actions
      • Unit - Create 1 Legionnaire for Player 1 (Red) at (Position of Spirit Healer 0029 <gen>) facing Default building facing degrees
      • Hero - Set (Last created unit) Hero-level to 30, Show level-up graphics
      • Unit - Create 20 Rifleman for Neutral Hostile at (Center of (Playable map area)) facing Default building facing degrees
      • Unit - Create 1 Knight for Player 1 (Red) at (Position of Spirit Healer 0029 <gen>) facing Default building facing degrees
      • Unit - Set life of (Last created unit) to 1.00%
(I know this leaks a lot but I'm going to import this to other map, this is only sandbox map)

Where can be the problem be that GetLastCreatedUnit() references to the Knight who is created at 0.00 after map init but the footman from JASS is created 2 seconds after map init and is not referenced as GetLastCreatedUnit?

P.S.:I'm still learning JASS so even if this is obvious I didn't find it after 30 minutes of trying.
 
The answer is in the BJ's definitions :
JASS:
//===========================================================================
function CreateUnitAtLocSaveLast takes player id, integer unitid, location loc, real face returns unit
    if (unitid == 'ugol') then
        set bj_lastCreatedUnit = CreateBlightedGoldmine(id, GetLocationX(loc), GetLocationY(loc), face)
    else
        set bj_lastCreatedUnit = CreateUnitAtLoc(id, unitid, loc, face)
    endif

    return bj_lastCreatedUnit
endfunction

//===========================================================================
function GetLastCreatedUnit takes nothing returns unit
    return bj_lastCreatedUnit
endfunction

//===========================================================================
function CreateNUnitsAtLoc takes integer count, integer unitId, player whichPlayer, location loc, real face returns group
    call GroupClear(bj_lastCreatedGroup)
    loop
        set count = count - 1
        exitwhen count < 0
        call CreateUnitAtLocSaveLast(whichPlayer, unitId, loc, face)
        call GroupAddUnit(bj_lastCreatedGroup, bj_lastCreatedUnit)
    endloop
    return bj_lastCreatedGroup
endfunction
The native CreateUnit doesn't save the unit in any variable. The way we do in jass is more something like that :
JASS:
function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    local unit footman
    set footman=CreateUnit(Player(0), 'hfoo', GetUnitX( gg_unit_H000_0029), GetUnitY(gg_unit_H000_0029), 0)
    call UnitApplyTimedLife( footman, 'BTLF', 0.01)
    set footman=null
endfunction

Or even like that if you need to refer the newly created unit only once :
JASS:
function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    call UnitApplyTimedLife( CreateUnit(Player(0), 'hfoo', GetUnitX( gg_unit_H000_0029), GetUnitY(gg_unit_H000_0029), 0), 'BTLF', 0.01)
endfunction
 
Status
Not open for further replies.
Top