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
  • Varine Varine:
    I ordered like five blocks for 15 dollars. They're just little aluminum blocks with holes drilled into them
  • Varine Varine:
    They are pretty much disposable. I have shitty nozzles though, and I don't think these were designed for how hot I've run them
  • Varine Varine:
    I tried to extract it but the thing is pretty stuck. Idk what else I can use this for
  • Varine Varine:
    I'll throw it into my scrap stuff box, I'm sure can be used for something
  • Varine Varine:
    I have spare parts for like, everything BUT that block lol. Oh well, I'll print this shit next week I guess. Hopefully it fits
  • Varine Varine:
    I see that, despite your insistence to the contrary, we are becoming a recipe website
  • Varine Varine:
    Which is unique I guess.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • 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 Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top