HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

JASS Trigger : Need Help!

06-13-2004, 06:49 PM#1
CTM
I was trying to make a trigger that would repeat a unit's attack animation when a certain chat string was entered, but it does not work. Here's the trigger :

Code:
function Trig_Animation_Loop_2_Func001Func001Func006001 takes nothing returns boolean
    if ( not ( GetIssuedOrderIdBJ() != String2OrderIdBJ("stop") ) ) then
         return false
    endif
    if ( not ( GetIssuedOrderIdBJ() != String2OrderIdBJ("hold") ) ) then
         return false
    endif
    return true
endfunction

function Trig_Animation_Loop_2_Func001Func001C takes nothing returns boolean
    if ( not ( IsUnitSelected(GetEnumUnit(), GetTriggerPlayer()) == true ) ) then
        return false
    endif
    if ( not ( GetOwningPlayer(GetEnumUnit()) == GetTriggerPlayer() ) ) then
        return false
    endif
    if ( not ( GetUnitTypeId(GetEnumUnit()) != 'hkni' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Animation_Loop_2_Func001A takes nothing returns nothing
    if ( Trig_Animation_Loop_2_Func001Func001C() ) then
        loop
           if Trig_Animation_Loop_2_Func001Func001Func006001() then
             call SetUnitAnimation( GetEnumUnit(), "attack" )
             exitwhen false
           endif
        endloop
    else
        call DoNothing(  )
    endif
endfunction

function Trig_Animation_Loop_2_Actions takes nothing returns nothing
    call ForGroupBJ( GetUnitsOfPlayerAll(Player(0)), function Trig_Animation_Loop_2_Func001A )
endfunction

//===========================================================================
function InitTrig_Animation_Loop_2 takes nothing returns nothing
    set gg_trg_Animation_Loop_2 = CreateTrigger(  )
    call TriggerRegisterPlayerChatEvent( gg_trg_Animation_Loop_2, Player(0), "play attack loop", true )
    call TriggerAddAction( gg_trg_Animation_Loop_2, function Trig_Animation_Loop_2_Actions )
endfunction
06-14-2004, 03:43 PM#2
fugly
i am not sure but i am thinking of getting rid of the "exitwhen false"
also you can get rid of else - do nothing and just finish it with an endif
06-14-2004, 04:14 PM#3
Cubasis
You are using event-response in a trigger that doesn't respond to the correct event. That is, you can only GetIssuedOrderBJ() when a trigger was run by a "A Unit ISsues a Order" event. You can't wait untill it happens. So you'll have to perform this differently.

~Cubasis
06-14-2004, 11:18 PM#4
CTM
Well then how do I make it loop until the order is something different than hold or stop?
06-14-2004, 11:36 PM#5
AIAndy
Check the current order of the unit. I think the native was something like GetUnitCurrentOrder or similar.
06-15-2004, 12:04 AM#6
Cubasis
And you have to work with a TriggerSleepAction for it too work properly, or your thread will crash very quickly.

So the pseudocode would be something like this:

Code:
loop
   exitwhen units current order = Stop/Stop
   Wait 0.25 //or sumtin
endloop

~Cubasis
06-15-2004, 12:35 AM#7
CTM
Mmm...is there any OR operator? Like exitwhen GetUnitCurrentOrder != "Stop" or GetUnitCurrentOrder != "Hold"


I tried :

Code:
        loop
             call SetUnitAnimation( GetEnumUnit(), "attack" )
             Wait 0.25
             exitwhen GetIssuedOrderIdBJ() != String2OrderIdBJ("stop")
        endloop

But it doesn't work. It says that at Wait 0.25 it expects endloop.

Nvm, I changed the Wait 0.25 to

Code:
call TriggerSleepAction( 0.25 )
^_^

Mmm...still not working. It doesn't loop. It does it once only. I want it to loop until the order changes to something else. It looks like it's not working :(

It just plays the animation then stops...
06-15-2004, 04:18 PM#8
AIAndy
or is the right operator there like you wrote.
But you are still using the event response function there which won't work. You need to use GetUnitCurrentOrder(my_unit)
06-15-2004, 07:19 PM#9
CTM
Replacing my_unit by GetEnumUnit() right? Or do I save the Picked Unit (GetEnumUnit()) as a variable then calling it using udg_my_unit?

I tried :

Code:
        loop
             call SetUnitAnimation( GetEnumUnit(), "attack" )
             call TriggerSleepAction( 0.25 )
             exitwhen GetUnitCurrentOrder( GetEnumUnit() ) != String2OrderIdBJ("stop")
        endloop
    else

Doesn't work though.
06-15-2004, 07:41 PM#10
AIAndy
ah, forgot something. I think you can't sleep in a group enumeration. That would explain why it does not work.
06-15-2004, 08:42 PM#11
CTM
So that would be why it doesn't loop? That's stupid...Shouldn't it loop anyway but not wait? Or does it wait endlessly?
06-15-2004, 08:44 PM#12
Cubasis
Quote:
Originally Posted by Cubasis
And you have to work with a TriggerSleepAction for it too work properly, or your thread will crash very quickly.

JASS doesn't work that way. It doesn't work to make it run endlessly. You have to wait. Becouse there is a inbuilt statement-limit, and if you run more statements than that without Waiting, JASS will kill the thread/trigger.

So you need to wait.

~Cubasis
06-15-2004, 08:52 PM#13
CTM
That's what I did using the TriggerSleep thing...but it just stops forever.