• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[vJASS] How do I wait for condition

Status
Not open for further replies.
Level 4
Joined
Nov 7, 2009
Messages
83
I'm writing a function inside a scope, and at the middle of the function I order the unit to attack and I need to wait until the unit reachs the target and attacks it. Can this be done?? How??

Consider that I am quite new to this, so I'm getting used to the language and the way it works (I also am new to common JASS).
 
Level 4
Joined
Nov 7, 2009
Messages
83
Yeah, I know that function, but I want to put it in the middle of a vJASS code, so I don't think that helps me a lot.
If possible, I would like to put a function or something in the middle of the code that is wait until condition "attack", then continue with the rest of the code. It's like when you place delays, wait for some time and then continue.
Maybe if I found how that function is called in JASS I could use it.

I've tried something like this
JASS:
        loop // loop until condition is met
            exitwhen (GetAttackedUnitBJ()==Target and GetAttacker()==Caster)==TRUE
        endloop
maybe if it could go inside a function, something like this
JASS:
    private function WaitForCondition takes conditionfunc Cond returns nothing
        loop // loop until condition is met
            exitwhen Cond==TRUE
        endloop
    endfunction
and evaluate continously until condition is met, and when condition is met exit the loop. So, I would put conditions looking for specified attacker and attacking unit and when they are met, it means I can continue with the spell.
 
Last edited:
Level 12
Joined
May 21, 2009
Messages
994
Sure you can do that e.g
JASS:
function set takes nothing returns nothing
local unit array u
local integer i = 1
set u[1] = gg_trg_Hpal_0000
set u[2] = gg_trg_Hfoo_0001
set u[3] = gg_trg_Hrif_0002
set u[4] = gg_trg_Hsor_0003
/////////////////////////////
loop
exitwhen GetUnitTypeId(udg_u[i]) == 'hfoo'
set i = i + 1
endfunction

This loops untill the unit type is footman is it like this you mean ??
 
Level 9
Joined
Nov 28, 2008
Messages
704
I would not recommend doing it that way. You need a wait.
To simulate the GUi action (actually, it's the same as the gui function)
JASS:
loop
    exitwhen (putaconditionhere)
    call PolledWait(0.1)
endloop
 
Level 4
Joined
Nov 7, 2009
Messages
83
I think I'm not making myself clear. I've tried this, but it didn't work (or at least, it seemed that it didn't work)
JASS:
    private function WaitForHit takes unit Caster, unit Target returns nothing
        loop // loop until condition is met
            exitwhen (GetAttackedUnitBJ()==Target and GetAttacker()==Caster)
            call PolledWait(0.1)
        endloop
    endfunction
Hope this makes it clearer on what I'm trying to do.
 
Level 9
Joined
Nov 28, 2008
Messages
704
You cant do that. Those functions only work when you have a trigger is fired on an attacked event. You're going to have to use some sort of struct or hashtable.
 
Level 4
Joined
Nov 7, 2009
Messages
83
Come on! I think there is a better way for detecting an attack than this
JASS:
    private function WaitForHit takes unit Caster, unit Target returns nothing
        loop // loop until condition is met
            exitwhen IsUnitInRange(Caster,Target,120)
            call PolledWait(0.1)
        endloop
    endfunction
and almost as short as this.
I fail to believe there isn't a simple way to detect damage and continue executing the main trigger function.

--------------------------------------------------------------------------

Also I would like to know: triggers are not like functions, if you execute them, they do not return to the point they were called from, am I wrong??
 
Status
Not open for further replies.
Top