Really really small waits

killingdyl

Active Member
Reaction score
6
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
Reaction score
413
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
Reaction score
6
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
 

Nestharus

o-o
Reaction score
84
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
Reaction score
6
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
Reaction score
42
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
Reaction score
42
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™
Reaction score
397
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
Reaction score
6
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
 

killingdyl

Active Member
Reaction score
6
Perfecto works like a charm! little slow but hey cant help it since im creating around 400 units +rep
 

Jesus4Lyf

Good Idea™
Reaction score
397
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:
 

Sevion

The DIY Ninja
Reaction score
413
T32 is difficult to learn? How o_O'

I think in terms of difficulty they go: KT2, TU, T32
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top