Simple JASS problem concerning last created unit

Bronxernijn

You can change this now in User CP.
Reaction score
43
Dear people, I tried something using the last created unit. All the code does is run the init function, it never gets to the second. What did I do wrong?

JASS:
scope unitPlus initializer init
    
    function try takes nothing returns nothing
        call DisplayTextToPlayer(Player(0), 0, 0, "Success!")
        call CreateUnit(Player(0), 'hfoo', 30, 30, 0)
    endfunction
    
    function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local unit u
        call CreateUnit(Player(0), 'hfoo', 0, 0, 0)
        set u = bj_lastCreatedUnit
        call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_SELECTED)
        call TriggerAddAction(t, function try)
    endfunction

endscope
 

GetTriggerUnit-

DogEntrepreneur
Reaction score
129
[lJASS]bj_lastCreateUnit[/lJASS] doesn't work for this function.

JASS:
scope unitPlus initializer init
    
    function try takes nothing returns nothing
        call DisplayTextToPlayer(Player(0), 0, 0, "Success!")
        call CreateUnit(Player(0), 'hfoo', 30, 30, 0)
    endfunction
    
    function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterUnitEvent(t, CreateUnit(Player(0), 'hfoo', 0, 0, 0), EVENT_UNIT_SELECTED)
        call TriggerAddAction(t, function try)
    endfunction

endscope


This could work or this too

JASS:

scope unitPlus initializer init
    
    function try takes nothing returns nothing
        call DisplayTextToPlayer(Player(0), 0, 0, "Success!")
        call CreateUnit(Player(0), 'hfoo', 30, 30, 0)
    endfunction
    
    function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        local unit u = CreateUnit(Player(0), 'hfoo', 0, 0, 0)
        call TriggerRegisterUnitEvent(t, u, EVENT_UNIT_SELECTED)
        call TriggerAddAction(t, function try)
    endfunction

endscope
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top