Really really small waits

killingdyl

Active Member
Ok i know i have to use a timer, but i dont know how to do that.

I want make my loop have a .01 seconds delay between each loop, this way it will draw on. How would i do that using timers?

Heres my loop:
JASS:
loop
        exitwhen i > 1080
        set xx = (r * (k - 1) * Cos((i) * bj_DEGTORAD)) + (r * Cos(((k - 1) * (i)) * bj_DEGTORAD))
        set xx = (xx + x)
        set yy = (r * (k - 1) * Sin((i) * bj_DEGTORAD)) - (r * Sin(((k - 1) * (i)) * bj_DEGTORAD))
        set yy = (yy + y)
        call CreateUnit(p, 'h004', xx, yy, 0)
        set i = i + 5
    endloop
 

Sevion

The DIY Ninja
Well, assuming you want MUI (if you're creating/changing handles), you'll have to "attach" data to a timer and run the timer with a callback doing these things.

Though, it'd be easier to figure out your situation's answer if we had the full code.
 

killingdyl

Active Member
heres the full code, and i dont want to use TSA cuz i know its inaccurate and i cant get the super small .01 second wait

the code isnt finished so dont tell me it will leak or i have unnecesarry variables.

JASS:
function Trig_Test_Conditions takes nothing returns boolean
    if ( not ( GetSpellAbilityId() == 'A004' ) ) then
        return false
    endif
    return true
endfunction

function Trig_Test_Actions takes nothing returns nothing
    local unit caster = GetTriggerUnit()
    local unit array dummy
    local player p = GetOwningPlayer(caster)
    local real x = GetUnitX(caster)
    local real y = GetUnitY(caster)
    local real xx
    local real yy
    local real r = 250
    local real k = 1.6666
    local integer i = 1
    local unit fog = null
    local group g = CreateGroup()
    loop
        exitwhen i > 1080
        set xx = (r * (k - 1) * Cos((i) * bj_DEGTORAD)) + (r * Cos(((k - 1) * (i)) * bj_DEGTORAD))
        set xx = (xx + x)
        set yy = (r * (k - 1) * Sin((i) * bj_DEGTORAD)) - (r * Sin(((k - 1) * (i)) * bj_DEGTORAD))
        set yy = (yy + y)
        call CreateUnit(p, 'h004', xx, yy, 0)
        set i = i + 5
    endloop
endfunction

//===========================================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Test, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Test, Condition( function Trig_Test_Conditions ) )
    call TriggerAddAction( gg_trg_Test, function Trig_Test_Actions )
endfunction
 
Make i a global named like iTrigTestLoop or something and store the index from there. Put the loop code into its own function and run it on a timer that's set for .032 if you want it to be super fast, however .2 is probably fast enough depending on what you are doing ; ).

If you have any other variables for it, just make them globals too.

A scope or a struct is highly suggested = ). You can store the instance of the struct into the timer so that you can have multiple instances of the loop going on at once.

Another method that will keep the loop going on forever is by putting it into a trigger as a triggercondition and evaluating that trigger forever. However, I would not suggest that as #1, it's instance, and #2, memory is not cleaned up until the cycle ends, so an infinite loop of that nature would eventually crash a computer.

So really, the timer method I talked about above is your best option ; ). It's best in a struct or at least a scope to support extensibility and maintainability, but it can be done in plain JASS with a few globals or even a few arrays.


Good luck : D.
 

killingdyl

Active Member
confused as hell! was just hoping for a little piece of code that would help me do that, or if someone can teach me how to do it in struct(whatever that is)
 

Strilanc

Veteran Scripter
You're going to have to use timers to perform the wait. Unfortunately, they don't allow you to just plop in a 'wait X time here' statement. Instead, they call a function when they expire. That means you need to somehow store your local variables and retrieve them in the called function.

There are several ways to associate data with a timer. The easiest is to just use a hashtable with GetHandleId(timer) as one of the keys.

So, in the method where you want to wait, you create the timer and store the necessary data in the hash table using the timer as the primary key. You then start the timer, pointing it at the method you want to run after the wait. In the called method, you use GetExpiredTimer as the primary key for retrieving the data you stored earlier.

Remember to clear out the saved data and destroy the timer.
 

Strilanc

Veteran Scripter
Well, your loop is essentially going to be a function called by a repeating timer. Quick example, which probably has a bunch of incorrect function names and typos:

JASS:

globals
    hashtable h = InitHashtable()
endglobals

private function Iterate takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local integer i = LoadInteger(h, GetHandleId(t), 0)

    //loop body
    call BJDebugMsg(I2S(i))

    //decrement stored 'i' for next loop    
    call SaveInteger(h, GetHandleId(t), 0, i-1)    

    //stop when i hits 0
    if i <= 0 then
        call StopTimer(t)
        call DestroyTimer(t)
        call ClearInteger(h, GetHandleId(t), 0)
    endif

    set t = null
endfunction

function StartIterate takes integer repeatCount returns nothing
    local timer t = CreateTimer()
    call SaveInteger(h, GetHandleId(t), 0, repeatCount)
    call TimerStart(t, 0.01, function Iterate)
    set t = null
endfunction
 

Jesus4Lyf

Good Idea™
This should be easy to understand. It executes a loop 32 times a second (every 0.03125 seconds - not 0.01 but it's better because it won't lag and still doesn't frame up horribly :)).

Requires T32.
JASS:
struct Trig_Test_Struct
    // local vars go here.
    unit caster = GetTriggerUnit()
    unit array dummy
    player p = GetOwningPlayer(caster)
    real x = GetUnitX(caster)
    real y = GetUnitY(caster)
    real xx
    real yy
    real r = 250
    real k = 1.6666
    integer i = 1
    unit fog = null
    group g = CreateGroup()
    
    method periodic takes nothing returns nothing
        // loop goes here.
        if i > 1080 then // <-- exitwhen
            // code after the loop goes here.
            // then add these lines.
            call this.stopPeriodic() // add this line.
            call this.destroy() // add this line.
            return // add this line.
        endif
        set xx = (r * (k - 1) * Cos((i) * bj_DEGTORAD)) + (r * Cos(((k - 1) * (i)) * bj_DEGTORAD))
        set xx = (xx + x)
        set yy = (r * (k - 1) * Sin((i) * bj_DEGTORAD)) - (r * Sin(((k - 1) * (i)) * bj_DEGTORAD))
        set yy = (yy + y)
        call CreateUnit(p, 'h004', xx, yy, 0)
        set i = i + 5
    endmethod
    
    implement T32x // magic.
    
    method act takes nothing returns nothing
        // things before the loop go here.
        call this.startPeriodic() // finish with this line.
    endmethod
endstruct

function Trig_Test_Actions takes nothing returns nothing
    // use this:
    call Trig_Test_Struct.create().act()
endfunction

That is an exact port of your code.
 

killingdyl

Active Member
i copied your code but it says that all my variables are undeclared, so i tried adding local in front of all of it and it says that some variables were redeclared or something like that
 

Jesus4Lyf

Good Idea™
Yay! I'm happy for you.

On a related note, I've seen people say that T32 is difficult to learn compared to TU or KT2. I'd like for people to note this thread, because it is actually the easiest to learn, in my opinion. Heck, if it's as simple as copy/paste and add a few lines, I doubt you can really go wrong. :thup:
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    Good luck to the hurricane path people. Is TH still in Houston?
  • Ghan Ghan:
    I think so
    +1
  • The Helper The Helper:
    Yeah we got nothing here did not even rain
  • Ghan Ghan:
    We could use some rain.
  • The Helper The Helper:
    I am not complaining though Hurricanes are not fun I have been through alot of them
  • Blackveiled Blackveiled:
    I evacuated for it just incase since I live in La Porte pretty much right on the water (in Houston area). Didn't see anything. It's a good thing for me anyways.
  • Ghan Ghan:
    It's too bad that Blizzard messed up so terribly with Reforged.
  • Ghan Ghan:
    Still has a 0.6 user metacritic score.
  • Ghan Ghan:
    (Out of 10)
  • Varine Varine:
    I haven't even tried it yet because everyone said it sucked. How do you get .6 out of ten?
  • The Helper The Helper:
    I am waiting for Dwarf Fortress to come out on Steam then I am on it.
  • Accname Accname:
    I play Dwarf Fortress from time to time.
  • Accname Accname:
    Its Okay.
  • Accname Accname:
    But the performance is sub-par. Does not seem to be well optimized.
  • Varine Varine:
    Is the Steam version coming with a graphical overlay or is it using the ASCII graphics still?
  • tom_mai78101 tom_mai78101:
    Steam version has the graphical overlay.
  • The Helper The Helper:
    Steam Version has graphics, a new interface and will be integrated in the steam mod stuff
  • Blackveiled Blackveiled:
    I didn't think WC3 Reforged was that bad. It pretty much did what it stated (to me at least), but then again I can care less about reforged campaigns and all that. I just care about gameplay.
  • Varine Varine:
    I think people were hoping for a resurgence in mod support. I have little interest in the actual game tbh
  • Varine Varine:
    Plus I know they added that Dota precedent clause where Blizzard can steal your shit which isn't cool.
  • Ghan Ghan:
    They sold Reforged to the community as primarily a huge graphical uplift with high res textures and redone cinematics.
  • Ghan Ghan:
    They even showed one of the redone cinematics at Blizzcon and that very cinematic wasn't even in the released game.
  • Ghan Ghan:
    So I think folks were angry about that.
  • Varine Varine:
    Didn't the backwards compatability have issues too?
  • Accname Accname:
    I never had any hopes for that. Blizzard is not the same company it was 10 years ago.

    Members online

    No members online now.

    Affiliates

    Hive Workshop
    Top