[Andrewgosu's JASS Corner]

Status
Not open for further replies.

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Basically, a thread, which will get flooded with my questions about JASS.

How exactly do I have to use function TriggerAddAction, if I want to add new actions to a local trigger?

Code:
    local integer i = GetIssuedOrderId()
    local real x = ( GetOrderPointX() + GetRandomReal( 30, 60 ) )
    local real y = ( GetOrderPointY() + GetRandomReal( 30, 60 ) )       
    
    if ( GetUnitState( ..., UNIT_STATE_LIFE ) == 0 ) then
        call DestroyTrigger( point )
    else
        call PolledWait( 1 )
        call IssuePointOrderById( ..., i, x, y )
    endif

If I want to add all these actions to a trigger, do I have to add them one by one?

Code:
function Trig_summon_Actions takes nothing returns nothing
    local trigger point = CreateTrigger()
    
    call TriggerRegisterUnitEvent( point, b, EVENT_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( point, local integer i = GetIssuedOrderId() )
    call TriggerAddAction( point, local real x = ( GetOrderPointX() + GetRandomReal( 30, 60 ) )
   ...ect.
endfunction
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
You don't add single lines, you add a function...

call TriggerAddAction( <the trigger>, function <some function>)


What happens if you add several functions to the same trigger?
No idea...
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Right, how foolish of me. I'll see, if I can make something work without greater explosions and casualties.
 

SFilip

Gone but not forgotten
Reaction score
633
For future reference: function TriggerAddAction takes a variable of type "code".
This is always a function that takes and returns nothing and is always "declared" the way AceHart wrote it function <code function name>.
Also note that TriggerAction needs to be destroyed before you destroy a trigger. I recommend using gamecache to attach it to a trigger after adding so that you can easily remove them to avoid the leak.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Code:
function Trig_summon_Actions takes nothing returns nothing
    local trigger point = CreateTrigger()
    
    call TriggerRegisterUnitEvent( point, b, EVENT_UNIT_ISSUED_POINT_ORDER )
    call TriggerAddAction( point, function point_Actions  )
[B]    call StoreInteger(LocalVars(), I2S(H2I(...)), "...", H2I(...))[/B]
endfunction

Code:
function point_Actions takes nothing returns nothing
    local integer i = GetIssuedOrderId()
    local real x = ( GetOrderPointX() + GetRandomReal( 30, 60 ) )
    local real y = ( GetOrderPointY() + GetRandomReal( 30, 60 ) )       
    
    if ( GetUnitState( ..., UNIT_STATE_LIFE ) == 0 ) then
[B]        GetStored...
        <TriggerRemoveActions?> ....[/B]
        call DestroyTrigger( point )
    else
        call PolledWait( 1 )
        call IssuePointOrderById( ..., i, x, y )
    endif
endfucntion

Basically, like this? How do I store the triggeraction via the Kattana's system?
 

emjlr3

Change can be a good thing
Reaction score
395
hrmmm well

local trigger trig = CreateTrigger()
call SetHandleHandle(trig,"ta",TriggerAddAction(trig,function blarg))

although i am rusty with that system, i use tables now, so it may be a little off

to remove

set trig = GetTriggeringTrigger()
call TriggerRemoveAction(trig,GetHandleTriggerAction(trig,"ta"))

again, i AM rusty
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
So, I add this piece of engineering to the system?

Code:
function GetHandleTriggerAction takes handle subject, string name returns triggeraction
    return GetStoredInteger(LocalVars(), I2S(H2I(subject)), name)
    return null
endfunction

Then, create and store the triggeraction like this: ( What about the action, which makes then event? Does it leak? )

Code:
function Trig_summon_Actions takes nothing returns nothing
    local trigger point = CreateTrigger()
    l[B]ocal triggeraction issue = TriggerAddAction( point, function point_Actions  )[/B]
    
    call TriggerRegisterUnitEvent( point, b, EVENT_UNIT_ISSUED_POINT_ORDER )
    [B]call StoreInteger(LocalVars(), I2S(H2I(point)), "issue", H2I(issue))[/B]
endfunction

And finally, destroy this like that?

Code:
function point_Actions takes nothing returns nothing
[B]    local trigger point = GetTriggeringTrigger()[/B]
    local integer i = GetIssuedOrderId()
    local real x = ( GetOrderPointX() + GetRandomReal( 30, 60 ) )
    local real y = ( GetOrderPointY() + GetRandomReal( 30, 60 ) )       
    
    if ( GetUnitState( ..., UNIT_STATE_LIFE ) == 0 ) then
[B]        call TriggerRemoveAction( point, GetHandleTriggerAction( point, "issue" ) )
        call DestroyTrigger( point )[/B]
    else
        call PolledWait( 1 )
        call IssuePointOrderById( ..., i, x, y )
    endif
endfucntion

I am too scared to save this in WE...
 

emjlr3

Change can be a good thing
Reaction score
395
looks about right

don't want to try in the WE???? well y not try JASSCraft ?
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Why does it say "Expected a function name"?

( emjlr3, I am using JassCraft )

Code:
function Trig_summon_Actions takes nothing returns nothing
    local unit a = GetSummonedUnit()
    local unit b = GetSummoningUnit()
    local trigger point = CreateTrigger()
    local triggeraction issue = TriggerAddAction( point, [B]function issue_same_order )[/B]
    
    call UnitAddAbility( a, 'Awan')
    call SetUnitOwner( a, Player(PLAYER_NEUTRAL_PASSIVE), false )    
    call TriggerRegisterUnitEvent( point, b, EVENT_UNIT_ISSUED_POINT_ORDER )
    
    call StoreInteger(LocalVars(), I2S(H2I(point)), "issue", H2I(issue))
    call StoreInteger(LocalVars(), I2S(H2I(point)), "a", H2I(a))
endfunction

//===========================================================================
function InitTrig_summon takes nothing returns nothing
    set gg_trg_summon = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_summon, EVENT_PLAYER_UNIT_SUMMON )
    call TriggerAddAction( gg_trg_summon, function Trig_summon_Actions )
endfunction

Code:
function [B]issue_same_order[/B] takes nothing returns nothing
    local trigger point = GetTriggeringTrigger()
    local integer i = GetIssuedOrderId()
    local real x =  GetOrderPointX() + GetRandomReal( 75, 150 ) 
    local real y =  GetOrderPointY() + GetRandomReal( 75, 150 )            
    local unit a = GetHandleUnit( point, "a" )

    if ( GetUnitState( a, UNIT_STATE_LIFE ) == 0 ) then
        call TriggerRemoveAction( point, GetHandleTriggerAction( point, "issue" ) )
        call DestroyTrigger( point )
    else
        call PolledWait( 1 )
        call IssuePointOrderById( a, i, x, y )
    endif
    
    set point = null
endfunction
 

emjlr3

Change can be a good thing
Reaction score
395
is issue_same_order not above Trig_summon_Actions ?

alos u dont need the triggeraction local, else u gotta set it to null later
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
This is bloody fantastic!

I thought the same, but it game me another error ( Which I don't remember ). Luckily, it works now and no ( noticable ) harm was done.
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Just a quick question about boolean expressions. Basically, they are the conditions used by the unit group? ( ...matching unit equals to...In GUI? ) How exactly do I use them?

local boolexpr b = ...( A some kind of condition? )
local group g = CreateGroup()
local location t = GetUnitLoc( GetTriggerUnit() )
call GroupEnumUnitsInRangeOfLoc( g, t, 300, b )

And what does GetFilterUnit() do?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,494
local boolexpr filter = Condition(function <some function>)

That function will be called for every unit in range, or owned by a player or whatever, depending on which "groupenum" you're using.

That function does some kind of test, and returns true or false.
With true, the unit that was tested will be in the group.
With false, it won't.

GetFilterUnit() refers to the current "matching unit".


You also need to destroy the filter after use:
call DestroyBoolExpr(filter)
set filter = null
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Thank You.


I have met an obscure error, which I cant quite fix.

"Invalid number of arguments"

The functions would be following.

Code:
constant function ancestral_unitcode takes nothing returns integer
    return 'n003' //Rawcode of the 'Ancestral Owl' unit.
endfunction

constant function ancestral_rawcode takes nothing returns integer
    return 'A002' //Rawcode of the 'Ancetral Owl' ability.
endfunction

constant function ancestral_healing_rawcode takes nothing returns integer
    return 'A000' //Rawcode of the 'Ancetral Owl' healing ability.
endfunction

And the function, which gives the error:

Code:
function Trig_ancestral_owl_Actions takes nothing returns nothing
    local unit    a   =   GetTriggerUnit( )
    local timer   t   =   CreateTimer( )
    local trigger f   =   GetTriggeringTrigger()
    local unit    b   
    
    if ( (GetIssuedOrderId() == OrderId(ancestral_orderid_turn_on())) and ( (GetUnitTypeId(a) == ancestral_unitcode()) ) ) then
        set b = CreateUnit( GetOwningPlayer(a), ancestral_unitcode( ), GetUnitX(a), GetUnitY(a), 0 )
        call SetHandleHandle( t, "a",  a )
        call SetHandleHandle( t, "b",  b )
        call SetHandleHandle( f, "b",  b )
        call TimerStart(t, 0.03, true, function ancestral_owl )
        call UnitAddAbility( b, ancestral_healing_rawcode( ) )
        call SetUnitAbilityLevel( b, GetUnitAbilityLevel( a, ancestral_rawcode( ) ) )
    else [COLOR="Red"]( (GetIssuedOrderId() == OrderId(ancestral_orderid_turn_off())) and ( (GetUnitTypeId(a) == ancestral_unitcode()) ) )[/COLOR]
        set b = GetHandleUnit( f, "b" )
        call RemoveUnit( b )
    endif    
endfunction


Any ideas?
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
I replaced the "else" with "elseif" and "then" at the end, but, it still gives the same error. :eek:

Can the error lie somewhere else? Just in case, I will post the whole code.
 

Steel

Software Engineer
Reaction score
109
Your problem is on the previous line. It's in your actions and I bolded the problem.
Code:
//============================================================================
//                          ACTIONS                                          =
//============================================================================
    
    if ( (GetIssuedOrderId() == OrderId(ancestral_orderid_turn_on())) and ( (GetUnitTypeId(a) == ancestral_unitcode()) ) ) then
        set b = CreateUnit( GetOwningPlayer(a), ancestral_unitcode( ), GetUnitX(a), GetUnitY(a), 0 )
        call SetHandleHandle( t, "a",  a )
        call SetHandleHandle( t, "b",  b )
        call SetHandleHandle( f, "b",  b )
        call TimerStart(t, 0.03, true, function ancestral_owl )
        call UnitAddAbility( b, ancestral_healing_rawcode( ) )
[b]        call SetUnitAbilityLevel( b, GetUnitAbilityLevel( a, ancestral_rawcode( ) ) )[/b]
    elseif ( (GetIssuedOrderId() == OrderId(ancestral_orderid_turn_off())) and ( (GetUnitTypeId(a) == ancestral_unitcode()) ) ) then
        set b = GetHandleUnit( f, "b" )
        call RemoveUnit( b )
    endif

The problem is that you misused SetUnitAbilityLevel. It is UNIT, ID, LEVEL, you are using it only as UNIT, ID. I didn't take the time to look at your code to try and understand it to fix it but I think it should be like this: call SetUnitAbilityLevel( b, ancestral_rawcode(), GetUnitAbilityLevel(a, ancestral_rawcode()))
 

Andrewgosu

The Silent Pandaren Helper
Reaction score
716
Thank You, fixed it. I also realized I was adding conditions to the trigger, but the condition function was missing. It has been fixed. Working as a charm, now.
 
Status
Not open for further replies.
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