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.
  • Ghan Ghan:
    I really do not want to move to California otherwise I might consider it.
  • The Helper The Helper:
    yeah California is not anywhere you really want to live
  • The Helper The Helper:
    That is why I did not take the job Blizzard offered me back in the day, there is no way I could have moved my family there on what they were offering, not even close and that was like 20 years ago
  • The Helper The Helper:
    yeah they wanted me on the tech support team when they did not get me they got one of the next MVPs in Dinobot
  • The Helper The Helper:
    Dinobot was one of the youngest of the MVPs tkron probably could have worked for Blizzard but he had a good job in Chicago doing business programming already
  • The Helper The Helper:
    Dinobot probably still works for Blizzard would love to reconnect with that guy
  • The Helper The Helper:
    I wonder what ever happened to Wargasm?
  • The Helper The Helper:
    This new version of Xenforo really is awesome
  • Ghan Ghan:
    Wargasm is still around. He works for the domain registrar where thehelper.net is kept.
  • Varine Varine:
    Is sqrage still around?
  • The Helper The Helper:
    I have not seen him on lately the forum says he was last on 2 years ago
  • The Helper The Helper:
    How are you doing Varine have not seen you around in a minute
  • thewrongvine thewrongvine:
    lol I live in CA
  • thewrongvine thewrongvine:
    I've got some friends in animation department who have been applying for Blizzard, doing interviews and such. They said the workplace seems nice, though now it'd be all remote work I suppose
  • The Helper The Helper:
    good for them I live close to Austin and am trying to get my kids interested in getting into Games but not having much luck. I would never let them move to Cali.
  • The Helper The Helper:
    unless it was huge money
  • The Helper The Helper:
    and even then with the taxes I really could never let them move there
  • thewrongvine thewrongvine:
    Haha fair enough, I have no interest in CA at all as a living place either. Really only here just for the work in LA, but hopefully once I get settled enough in my work, I can move out
    +1
  • Ghan Ghan:
    +1
  • jonas jonas:
    " a traditionally-sized California family of one person ":cool:
    +1

    Staff online

    • Ghan
      Administrator - Servers are fun

    Members online

    Affiliates

    Hive Workshop
    Top