Smooth periodics - turning off

Cokemonkey11

New Member
Reaction score
18
As I noted in this thread - http://www.thehelper.net/forums/showthread.php?t=107530

I turned .1 second wait action into a more final draft of every .03 game seconds.

Here is my code currently.

JASS:
globals
unit centerUnit
unit rifleAttacker
unit footAttacked
integer i
endglobals

function moveInCircle takes nothing returns nothing
    local location posCenter = GetUnitLoc(centerUnit)
    local location posCenterOff
    local real posRifleOffX
    local real posRifleOffY
    local location posCenterOff2
    local real posFootOffX
    local real posFootOffY
    set i = i+1
    set posCenterOff = PolarProjectionBJ(posCenter,512,i)
    set posRifleOffX = GetLocationX(posCenterOff)
    set posRifleOffY = GetLocationY(posCenterOff)
    set posCenterOff2 = PolarProjectionBJ(posCenter,450,i)
    set posFootOffX = GetLocationX(posCenterOff2)
    set posFootOffY = GetLocationY(posCenterOff2)
    call SetUnitX(rifleAttacker,posRifleOffX)
    call SetUnitY(rifleAttacker,posRifleOffY)
    call SetUnitX(footAttacked,posFootOffX)
    call SetUnitY(footAttacked,posFootOffY)
endfunction

function Trig_dummyCenter_Actions takes nothing returns nothing
    local timer time = CreateTimer()
    set centerUnit = CreateUnitAtLoc(Player(0),'hfoo',GetRectCenter(GetPlayableMapRect()),270)
    set rifleAttacker = CreateUnitAtLoc(Player(15),'hrif',PolarProjectionBJ(GetRectCenter(GetPlayableMapRect()),512,0),270)
    set footAttacked = CreateUnitAtLoc(Player(15),'hfoo',PolarProjectionBJ(GetRectCenter(GetPlayableMapRect()),390,0),270)
    call IssueTargetOrder(rifleAttacker,"attack",footAttacked)
    set i = 0
    call TimerStart(time,.03,true,function moveInCircle)
endfunction

function InitTrig_movingCircleFast takes nothing returns nothing
    set gg_trg_movingCircleFast = CreateTrigger()
    call TriggerRegisterTimerEvent(gg_trg_movingCircleFast,2,false)
    call TriggerAddAction(gg_trg_movingCircleFast, function Trig_dummyCenter_Actions)
endfunction


My question is - how do I stop the rotation from running without just "masking" it. I want the trigger to actually stop calling every .03 seconds.
Maybe an if then that says after 360 degrees cancel timer or something.

My other question is - You will see in this video http://www.xfire.com/video/30a05/ of my trigger running that the rifleman starts to attack the footman but after awhile he just stops and they both start trying to "walk" back to their original placed position. Is there any simple way of avoiding this? I think I could just put order rifle to attack footman at the loop every time, but then again maybe that won't work.

AFTER these questions I will be interested in ways of cleaning up/making better my trigger. But please don't just say DO THIS DO THAT, I'd like an explanation of whats changing and why it's better.
 

Dr.Jack

That's Cap'n to you!
Reaction score
109
My question is - how do I stop the rotation from running without just "masking" it. I want the trigger to actually stop calling every .03 seconds.

Assuming I understood you properly if you want to make the unit stop rotating after a while use ticks. Here you make the rifleman more 1 degree at a time, meaning it takes him 360 times runs to complete a round. So set ticks = 360. Pass the information to the callback function and reduce it by 1 each run until ticks == 0. Then destroy the timer and the rifleman will stop rotating after one round. Clear I hope?

> My other question is - You will see in this video http://www.xfire.com/video/30a05/ of my trigger running that the rifleman starts to attack the footman but after awhile he just stops and they both start trying to "walk" back to their original placed position

Mind rephrasing?

> AFTER these questions I will be interested in ways of cleaning up/making better my trigger. But please don't just say DO THIS DO THAT, I'd like an explanation of whats changing and why it's better.

You got several leaks here I strongly suggest you read some leak removing tutorials. Also I suggest you use natives rather then BJs. If you need anymore assistance in this area let us know!
 

Cokemonkey11

New Member
Reaction score
18
I think I get what you mean by ticks - its just like in a loop when you say exitwhen n = 500 and then do set n = n+1 right?

If i implemented ticks +1 each time and i wanted it to stop at 360, what would the code be after that to stop the trigger?


If you watch the video you will see the rifleman is attacking the footman. But after a short while, they just stop and begin playing their walk animation trying to walk back to their starting position (?)

leaks I need to work on, and is there any specific BJ you see that should be replaced with a native? (I've read a few tutorials on making clean code) I know I should ideally make every BJ into native code, but is there any one I'm using in particular you think I should change?
 

quraji

zap
Reaction score
144
JASS:
globals
    integer counter = 0
endglobals

function runthrice takes nothing returns nothing
    local timer t = GetExpiredTimer()

    set counter  = counter + 1

    if counter == 3 then
        call PauseTimer(t)
        call DestroyTimer(t)
        set t = null
        return
    endif

endfunction

function startit takes nothing returns nothing
    local timer t = CreateTimer()

    call TimerStart(t, .03, true, function runthrice)

endfunction


Obviously not multi-instanceable. Use gamecache with(out) structs, or an attachment system to achieve this..ask if you need an example.
 

AdamGriffith

You can change this now in User CP.
Reaction score
69
JASS:
scope MoveInCircle initializer Init     //Seeing as you are using vJASS you might aswell take advantage of scopes.

globals     //It is just 'convention' to use block capitals for global names.
    unit CENTERUNIT
    unit RIFLEATTACKER
    unit FOOTATTACKED
    integer I = 0
endglobals

private function Move takes nothing returns nothing
    local real x1 = GetUnitX(CENTERUNIT)
    local real y1 = GetUnitY(CENTERUNIT)
    local real x2
    local real y2
    local real x3
    local real y3
    local timer t = GetExpiredTimer()

    set I = I + 1
    set x2 = x1 + 512.0 * Cos(I * bj_DEGTORAD)      //Use reals instead of locations. Faster? And then dont need to be cleaned.
    set y2 = y1 + 512.0 * Sin(I * bj_DEGTORAD)
    set x3 = x1 + 384.0 * Cos(I * bj_DEGTORAD)
    set y3 = y1 + 384.0 * Sin(I * bj_DEGTORAD)
    call SetUnitPosition(RIFLEATTACKER, x2, y2)     //Better than setting x and y seperately.
    call SetUnitPosition(FOOTATTACKED, x3, y3)      //Better than setting x and y seperately.
    if I == 360 then        //This is to stop everything at 360 degrees.
        set I = 0
        call PauseTimer(t)
        call DestroyTimer(t)
    else
    endif
    
    set t = null        //Cleaning our ONE handle leak. <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite1" alt=":)" title="Smile    :)" loading="lazy" data-shortname=":)" />
endfunction

private function Actions takes nothing returns nothing      //This is now private so it can just be called actions.
    local timer t = CreateTimer()
    set CENTERUNIT = CreateUnit(Player(0), &#039;hfoo&#039;, 0.0, 0.0, 270.0)       //Lets use reals instead of locations.
    set RIFLEATTACKER = CreateUnit(Player(15), &#039;hrif&#039;, 512.0, 0.0, 270.0)       //Just changed to use reals.
    set FOOTATTACKED = CreateUnit(Player(15), &#039;hfoo&#039;, 384.0, 0.0, 270.0)        //Just changed to use reals.
    call IssueTargetOrder(RIFLEATTACKER, &quot;attack&quot;, FOOTATTACKED)        //Are you sure this is what you meant to do?
    call TimerStart(t, 0.03, true, function Move)
    set t = null
endfunction

private function Init takes nothing returns nothing     //This can now just be called init because it is inside of the scope.
    local trigger t = CreateTrigger()       //Make this local.
    call TriggerRegisterTimerEvent(t,2.0,false)
    call TriggerAddAction(t, function Actions)
endfunction

endscope    //End of the scope.


Quick jobbie. Tell me if there is a problem.

EDIT:
Also this is not MUI.

And for the walk animation thing, I think you are going to have to order the units to stop each time the timer runs.
 
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

      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