Spot the differences +REP

Lightstalker

New Member
Reaction score
55
So once upon a time, in 20 minutes, I made this gigantic multi-trigger that moves a unit based on arrow keys pressed.

JASS:
scope Movement initializer Init

private function Actions takes nothing returns nothing
    local real angle = 0.0
    local real x = 0.0
    local real y = 0.0
    local integer i = 0
    
    loop
        if LEFTBOOLEAN<i> and UPBOOLEAN<i> == true then
            set angle = 135.0
            set x = GetUnitX(FIGHTER<i>) + 1024 * Cos(angle * bj_DEGTORAD)
            set y = GetUnitY(FIGHTER<i>) + 1024 * Sin(angle * bj_DEGTORAD)
            call IssuePointOrder(FIGHTER<i>, &quot;move&quot;, x, y)
        elseif LEFTBOOLEAN<i> and DOWNBOOLEAN<i> == true then
            set angle = 235.0
            set x = GetUnitX(FIGHTER<i>) + 1024 * Cos(angle * bj_DEGTORAD)
            set y = GetUnitY(FIGHTER<i>) + 1024 * Sin(angle * bj_DEGTORAD)
            call IssuePointOrder(FIGHTER<i>, &quot;move&quot;, x, y)
        elseif RIGHTBOOLEAN<i> and UPBOOLEAN<i> == true then
            set angle = 45.0
            set x = GetUnitX(FIGHTER<i>) + 1024 * Cos(angle * bj_DEGTORAD)
            set y = GetUnitY(FIGHTER<i>) + 1024 * Sin(angle * bj_DEGTORAD)
            call IssuePointOrder(FIGHTER<i>, &quot;move&quot;, x, y)
        elseif RIGHTBOOLEAN<i> and DOWNBOOLEAN<i> == true then
            set angle = 315.0
            set x = GetUnitX(FIGHTER<i>) + 1024 * Cos(angle * bj_DEGTORAD)
            set y = GetUnitY(FIGHTER<i>) + 1024 * Sin(angle * bj_DEGTORAD)
            call IssuePointOrder(FIGHTER<i>, &quot;move&quot;, x, y)
            
            elseif LEFTBOOLEAN<i> == true then
                set angle = 180.0
                set x = GetUnitX(FIGHTER<i>) + 1024 * Cos(angle * bj_DEGTORAD)
                set y = GetUnitY(FIGHTER<i>) + 1024 * Sin(angle * bj_DEGTORAD)
                call IssuePointOrder(FIGHTER<i>, &quot;move&quot;, x, y)
            elseif RIGHTBOOLEAN<i> == true then
                set angle = 0.0
                set x = GetUnitX(FIGHTER<i>) + 1024 * Cos(angle * bj_DEGTORAD)
                set y = GetUnitY(FIGHTER<i>) + 1024 * Sin(angle * bj_DEGTORAD)
                call IssuePointOrder(FIGHTER<i>, &quot;move&quot;, x, y)
            elseif UPBOOLEAN<i> == true then
                set angle = 90.0
                set x = GetUnitX(FIGHTER<i>) + 1024 * Cos(angle * bj_DEGTORAD)
                set y = GetUnitY(FIGHTER<i>) + 1024 * Sin(angle * bj_DEGTORAD)
                call IssuePointOrder(FIGHTER<i>, &quot;move&quot;, x, y)
            elseif DOWNBOOLEAN<i> == true then
                set angle = 270.0
                set x = GetUnitX(FIGHTER<i>) + 1024 * Cos(angle * bj_DEGTORAD)
                set y = GetUnitY(FIGHTER<i>) + 1024 * Sin(angle * bj_DEGTORAD)
                call IssuePointOrder(FIGHTER<i>, &quot;move&quot;, x, y)
            endif
    set i = i + 1
    exitwhen i &gt; 11
    endloop
endfunction

private function MoveLeft takes nothing returns nothing
    local integer pid = GetPlayerId(GetTriggerPlayer())
    local real angle = 180.0
    local real x = GetUnitX(FIGHTER[pid]) + 1024 * Cos(angle * bj_DEGTORAD)
    local real y = GetUnitY(FIGHTER[pid]) + 1024 * Sin(angle * bj_DEGTORAD)
    
    set LEFTBOOLEAN[pid] = true
    call IssuePointOrder(FIGHTER[pid], &quot;move&quot;, x, y)
endfunction
private function StopLeft takes nothing returns nothing
    local integer pid = GetPlayerId(GetTriggerPlayer())
    set LEFTBOOLEAN[pid] = false
    call IssueImmediateOrder(FIGHTER[pid], &quot;stop&quot;)
endfunction

private function MoveRight takes nothing returns nothing
    local integer pid = GetPlayerId(GetTriggerPlayer())
    local real angle = 0.0
    local real x = GetUnitX(FIGHTER[pid]) + 1024 * Cos(angle * bj_DEGTORAD)
    local real y = GetUnitY(FIGHTER[pid]) + 1024 * Sin(angle * bj_DEGTORAD)
    
    set RIGHTBOOLEAN[pid] = true
    call IssuePointOrder(FIGHTER[pid], &quot;move&quot;, x, y)
endfunction
private function StopRight takes nothing returns nothing
    local integer pid = GetPlayerId(GetTriggerPlayer())
    set RIGHTBOOLEAN[pid] = false
    call IssueImmediateOrder(FIGHTER[pid], &quot;stop&quot;)
endfunction

private function MoveUp takes nothing returns nothing
    local integer pid = GetPlayerId(GetTriggerPlayer())
    local real angle = 90.0
    local real x = GetUnitX(FIGHTER[pid]) + 1024 * Cos(angle * bj_DEGTORAD)
    local real y = GetUnitY(FIGHTER[pid]) + 1024 * Sin(angle * bj_DEGTORAD)
    
    set UPBOOLEAN[pid] = true
    call IssuePointOrder(FIGHTER[pid], &quot;move&quot;, x, y)
endfunction
private function StopUp takes nothing returns nothing
    local integer pid = GetPlayerId(GetTriggerPlayer())
    set UPBOOLEAN[pid] = false
    call IssueImmediateOrder(FIGHTER[pid], &quot;stop&quot;)
endfunction


private function MoveDown takes nothing returns nothing
    local integer pid = GetPlayerId(GetTriggerPlayer())
    local real angle = 270.0
    local real x = GetUnitX(FIGHTER[pid]) + 1024 * Cos(angle * bj_DEGTORAD)
    local real y = GetUnitY(FIGHTER[pid]) + 1024 * Sin(angle * bj_DEGTORAD)
    
    set DOWNBOOLEAN[pid] = true
    call IssuePointOrder(FIGHTER[pid], &quot;move&quot;, x, y)
endfunction
private function StopDown takes nothing returns nothing
    local integer pid = GetPlayerId(GetTriggerPlayer())
    set DOWNBOOLEAN[pid] = false
    call IssueImmediateOrder(FIGHTER[pid], &quot;stop&quot;)
endfunction

private function Init takes nothing returns nothing
    local trigger pressleft = CreateTrigger()
    local trigger releaseleft = CreateTrigger()
    
    local trigger pressright = CreateTrigger()
    local trigger releaseright = CreateTrigger()
    
    local trigger pressup = CreateTrigger()
    local trigger releaseup = CreateTrigger()
    
    local trigger pressdown = CreateTrigger()
    local trigger releasedown = CreateTrigger()

    local integer i = 0
    local trigger t = CreateTrigger()
    call TriggerRegisterTimerEvent(t, 0.333, true)
    loop
        
        call TriggerRegisterPlayerKeyEventBJ(pressleft, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_LEFT)
        call TriggerRegisterPlayerKeyEventBJ(releaseleft, Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_LEFT)
        
        call TriggerRegisterPlayerKeyEventBJ(pressright, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_RIGHT)
        call TriggerRegisterPlayerKeyEventBJ(releaseright, Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_RIGHT)
        
        call TriggerRegisterPlayerKeyEventBJ(pressup, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_UP)
        call TriggerRegisterPlayerKeyEventBJ(releaseup, Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_UP)
        
        call TriggerRegisterPlayerKeyEventBJ(pressdown, Player(i), bj_KEYEVENTTYPE_DEPRESS, bj_KEYEVENTKEY_DOWN)
        call TriggerRegisterPlayerKeyEventBJ(releasedown, Player(i), bj_KEYEVENTTYPE_RELEASE, bj_KEYEVENTKEY_DOWN)
    set i = i + 1
    exitwhen i &gt; 11
    endloop
    
    call TriggerAddAction(t, function Actions)
    
    call TriggerAddAction(pressleft, function MoveLeft)
    call TriggerAddAction(releaseleft, function StopLeft)
    
    call TriggerAddAction(pressright, function MoveRight)
    call TriggerAddAction(releaseright, function StopRight)
    
    call TriggerAddAction(pressup, function MoveUp)
    call TriggerAddAction(releaseup, function StopUp)
    
    call TriggerAddAction(pressdown, function MoveDown)
    call TriggerAddAction(releasedown, function StopDown)
endfunction
endscope</i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i></i>


I then decided to optimize it (and by that I mean cut it up into different triggers), but it would not work correctly anymore:

JASS:
scope MoveLeft initializer Init
    
    private function Move takes nothing returns nothing
        local integer pid = GetPlayerId(GetTriggerPlayer())
        local real angle = 180.0
        local real x = GetUnitX(FIGHTER[pid]) + 1024 * Cos(angle * bj_DEGTORAD)
        local real y = GetUnitY(FIGHTER[pid]) + 1024 * Sin(angle * bj_DEGTORAD)
        
        set LEFTBOOLEAN[pid] = true
        call IssuePointOrder(FIGHTER[pid], &quot;move&quot;, x, y)
    endfunction
    
    private function Stop takes nothing returns nothing
        local integer pid = GetPlayerId(GetTriggerPlayer())
        set LEFTBOOLEAN[pid] = false
        call IssueImmediateOrder(FIGHTER[pid], &quot;stop&quot;)
    endfunction

    private function Init takes nothing returns nothing
        local integer i = 0
        local trigger press = CreateTrigger()
        local trigger release = CreateTrigger()
        
        loop
            call TriggerRegisterPlayerEvent(press, Player(i), EVENT_PLAYER_ARROW_LEFT_DOWN)
            call TriggerRegisterPlayerEvent(release, Player(i), EVENT_PLAYER_ARROW_LEFT_UP)
        set i = i + 1
        exitwhen i == 12
        endloop
        call TriggerAddAction(press, function Move)
        call TriggerAddAction(release, function Stop)
    endfunction
endscope


For some reason, the unit will move left, and then stop and attempt to move in every direction at once.
 

ZugZugZealot

New Member
Reaction score
33
You lack something that tells it to "keep going". The first one has a periodic trigger which keeps track of when a key is down or up and moves every 1/3rd second while the key press events merely set a boolean for the periodic to read (press event set to true; release event set to false). The second one merely tells the unit to be moved once upon the arrow key event.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Howdy
  • 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 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