Calling a function with waits in it

s3rius

Linux is only free if your time is worthless.
Reaction score
130
Hi,
my problem is that I'm calling a function that uses waits in a loop, thus the loop waits until the function's waits are over. How can I get the loop to immediately continue?
That's the code, MSRL_Actions is the function with the loop, FireRocketLauncher with the waits.
JASS:

function FireRocketLauncher takes unit u, integer lvl, location spellloc returns nothing //which unit fires, level of rocket, target
    local player my_player = GetOwningPlayer( u)
    local location my_unitloc = GetUnitLoc( u)
    local unit my_dummy = CreateUnitAtLoc(my_player, 'h00K', my_unitloc , 270.00)
    
    call IssuePointOrderLoc( my_dummy, "attackground", spellloc )
    call SetUnitAbilityLevel(my_dummy, 'A00T', lvl)
    call PolledWait( ( DistanceBetweenPoints(my_unitloc, spellloc) / 1400.00 ) * 1.1 ) //That's the wait -.-
    call IssuePointOrderLoc( my_dummy, "blizzard", spellloc )
    call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl", spellloc))
    call UnitDamagePoint( u, 0, 140 + (lvl * 10), GetLocationX(spellloc), GetLocationY(spellloc), 230 + (20 * lvl), true, true, ATTACK_TYPE_MELEE, DAMAGE_TYPE_DEMOLITION, WEAPON_TYPE_WHOKNOWS)
    call AttachSoundToUnit(gg_snd_GrenadeExplosion, my_dummy)
    call SetSoundVolume(gg_snd_GrenadeExplosion, 200)
    call StartSound(gg_snd_GrenadeExplosion)
    call UnitApplyTimedLife(my_dummy, 'BTLF', 2.00)
    call RemoveUnit(my_dummy)
    set my_dummy = null
    set my_unitloc = null
    set my_player = null
endfunction

function MSRL_Actions takes nothing returns nothing
    local unit my_unit = GetTriggerUnit()
    local integer my_integer = 5
    local location my_targloc 
    local location my_location = GetSpellTargetLoc()

    loop
        exitwhen my_integer == 0
        set my_targloc = GetRandomPointInRange( GetLocationX(my_location), GetLocationY(my_location), 250)
        call FireRocketLauncher(my_unit, 3, my_targloc)
        set my_integer = my_integer - 1
    endloop
    set my_unit = null
    set my_targloc = null
endfunction

BTW that wait is needed because without it the explosion would occur when the rocket is still in the air´.
 

The_Kingpin

Member (Who are you and why should I care?)
Reaction score
41
You can't unless you start a new thread with ExecuteFunc() or you do something with timers.

P.S. You also didn't RemoveLocation() your locations and some are not set = null ed.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Yes The_Kingpin is right. Use struct to trasfer the arguements and use timers or ExecuteFunc.
 

s3rius

Linux is only free if your time is worthless.
Reaction score
130
Well, I'm pretty much new to structs and stuff like this. I've read DuckieKing's tutorial but it's still a bit too much for me. :eek:
Could you explain me in short what I have to put into the struct?
I don't want the complete trigger, just a little help :)
 

0zaru

Learning vJASS ;)
Reaction score
60
try TriggerSleepAction instead of polledwait, anyway it isn't very accurate do that.
 

s3rius

Linux is only free if your time is worthless.
Reaction score
130
triggersleep has the same effect than polledwait has.
 

0zaru

Learning vJASS ;)
Reaction score
60
all though polledwait uses a timer instead and a loop to determine when ends:

JASS:
function PolledWait takes real duration returns nothing
    local timer t
    local real  timeRemaining

    if (duration > 0) then
        set t = CreateTimer()
        call TimerStart(t, duration, false, null)
        loop
            set timeRemaining = TimerGetRemaining(t)
            exitwhen timeRemaining <= 0

            // If we have a bit of time left, skip past 10% of the remaining
            // duration instead of checking every interval, to minimize the
            // polling on long waits.
            if (timeRemaining > bj_POLLED_WAIT_SKIP_THRESHOLD) then
                call TriggerSleepAction(0.1 * timeRemaining)
            else
                call TriggerSleepAction(bj_POLLED_WAIT_INTERVAL)
            endif
        endloop
        call DestroyTimer(t)
    endif
endfunction


try at least =P may work or not it's a suggestion. Try it at least =P
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
PolledWait is more accurate than TriggerSleepAction, but PolledWait leaks.

You'll have to put in the struct simply all the arguements you want to pass to the function, and then find a way to trasfer the struct to the trigger, perhaps by using globals, gamecache or handlevars.
 

SFilip

Gone but not forgotten
Reaction score
634
> PolledWait is more accurate than TriggerSleepAction
Not quite - the primary purpose of PolledWait is that it's not affected by lag while TriggerSleepAction is. In other words, if you run a one minute TriggerSleepAction for example and someone starts lagging, the game will not pause this wait, it will still keep going while PolledWait would stop and continue once the lag is over.
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
... Thus PolledWait is more accurate becuase it will continue working even with problems such as lags. I didn't put it clearly enough it seems.
 

Arkan

Nobody rides for free
Reaction score
92
Use ExecuteFunc(), or if you have NewGen, you can use functionname.execute(argument1, argument2) to pass aguments, very handy.
 

s3rius

Linux is only free if your time is worthless.
Reaction score
130
Ok, it took my the whole evening to figure out how to work with structs :p
Well, now my ability works fine except of the nasty message "double free of location in FireRocketLauncher". That's my code so far.
JASS:

struct RocketBarrage //Used for Rocket Launcher and MSRL
    unit caster //casting unit
    location spellloc //targeted loc
    location unitloc //caster's loc
    integer level //level of rocket launcher ability
endstruct

function FireRocketLauncher takes nothing returns nothing
    local RocketBarrage Data=1
    local player my_player = GetOwningPlayer( Data.caster)
    local location my_unitloc = GetUnitLoc( Data.caster)
    local location my_spellloc = Data.spellloc
    local integer my_lvl = Data.level
    local unit my_dummy = CreateUnitAtLoc(my_player, 'h00K', my_unitloc , 270.00)
    
    call IssuePointOrderLoc( my_dummy, "attackground", my_spellloc )
    call SetUnitAbilityLevel(my_dummy, 'A00T', my_lvl)
    call PolledWait( ( DistanceBetweenPoints(my_unitloc, my_spellloc) / 1400.00 ) * 1.1 )
    call IssuePointOrderLoc( my_dummy, "blizzard", my_spellloc )
    call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl", my_spellloc))
    call UnitDamagePoint( Data.caster, 0, 140 + (my_lvl * 10), GetLocationX(my_spellloc), GetLocationY(my_spellloc), 230 + (20 * my_lvl), true, true, ATTACK_TYPE_MELEE, DAMAGE_TYPE_DEMOLITION, WEAPON_TYPE_WHOKNOWS)
    call AttachSoundToUnit(gg_snd_GrenadeExplosion, my_dummy)
    call SetSoundVolume(gg_snd_GrenadeExplosion, 200)
    call StartSound(gg_snd_GrenadeExplosion)
    call UnitApplyTimedLife(my_dummy, 'BTLF', 1.00)
    
    set my_dummy = null
    call RemoveLocation(my_unitloc)
    call RemoveLocation(my_spellloc)
    set my_unitloc = null
    set my_spellloc = null
    set my_player = null
endfunction

function MSRL_Actions takes nothing returns nothing
    local unit my_unit = GetTriggerUnit()
    local integer my_integer = 5
    local location my_targloc 
    local location my_spellloc = GetSpellTargetLoc()
    local RocketBarrage Data = RocketBarrage.create()
    set Data.unitloc = GetUnitLoc(my_unit)
    set Data.level = GetUnitAbilityLevel( my_unit, 'S001')
    set Data.caster = my_unit

    loop
        exitwhen my_integer == 0
        set my_targloc = GetRandomPointInRange( GetLocationX(my_spellloc), GetLocationY(my_spellloc), 250)
        set Data.spellloc = my_targloc

        call SetUnitUserData(my_unit, 1)
        call ExecuteFunc("FireRocketLauncher")
        call PolledWait(0.1) //tried with and without this wait
        set my_integer = my_integer - 1
    endloop
    set my_unit = null
    call RemoveLocation(my_targloc)
    call RemoveLocation(my_spellloc)
    set my_targloc = null
    set my_spellloc = null
    call Data.destroy()
endfunction
 

Vexorian

Why no custom sig?
Reaction score
187
Ok, it took my the whole evening to figure out how to work with structs
You kind of have wasted your time...

In your case, you didn't need structs you only needed this:

JASS:
function FireRocketLauncher takes unit u, integer lvl, location spellloc returns nothing //which unit fires, level of rocket, target
    local player my_player = GetOwningPlayer( u)
    local location my_unitloc = GetUnitLoc( u)
    local unit my_dummy = CreateUnitAtLoc(my_player, 'h00K', my_unitloc , 270.00)
    
    call IssuePointOrderLoc( my_dummy, "attackground", spellloc )
    call SetUnitAbilityLevel(my_dummy, 'A00T', lvl)
    call PolledWait( ( DistanceBetweenPoints(my_unitloc, spellloc) / 1400.00 ) * 1.1 ) //That's the wait -.-
    call IssuePointOrderLoc( my_dummy, "blizzard", spellloc )
    call DestroyEffect(AddSpecialEffectLoc("Abilities\\Spells\\Orc\\WarStomp\\WarStompCaster.mdl", spellloc))
    call UnitDamagePoint( u, 0, 140 + (lvl * 10), GetLocationX(spellloc), GetLocationY(spellloc), 230 + (20 * lvl), true, true, ATTACK_TYPE_MELEE, DAMAGE_TYPE_DEMOLITION, WEAPON_TYPE_WHOKNOWS)
    call AttachSoundToUnit(gg_snd_GrenadeExplosion, my_dummy)
    call SetSoundVolume(gg_snd_GrenadeExplosion, 200)
    call StartSound(gg_snd_GrenadeExplosion)
    call UnitApplyTimedLife(my_dummy, 'BTLF', 2.00)
    call RemoveUnit(my_dummy)
    set my_dummy = null
    set my_unitloc = null
    set my_player = null
endfunction

function MSRL_Actions takes nothing returns nothing
    local unit my_unit = GetTriggerUnit()
    local integer my_integer = 5
    local location my_targloc 
    local location my_location = GetSpellTargetLoc()

    loop
        exitwhen my_integer == 0
        set my_targloc = GetRandomPointInRange( GetLocationX(my_location), GetLocationY(my_location), 250)
        call FireRocketLauncher.execute(my_unit, 3, my_targloc)
        set my_integer = my_integer - 1
    endloop
    set my_unit = null
    set my_targloc = null
endfunction


Your code with structs is just TERRIBLY wrong. Try learning structs another day, one of the times you actually need structs to solve your problem.
 

The_Kingpin

Member (Who are you and why should I care?)
Reaction score
41
The way you are using your structs will work, but if two units cast it while the effect is already running... well... then you've got problems...
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top