Trigger causing lag

Wratox1

Member
Reaction score
22
Hello, i have some problem with my map, i have a spell, which creates a bullet:
Trigger:
  • machinegun
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Machinegun
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • machinegunammo[(Player number of (Owner of (Triggering unit)))] Greater than or equal to 5
        • Then - Actions
          • For each (Integer bulletint[(Player number of (Owner of (Triggering unit)))]) from 1 to 5, do (Actions)
            • Loop - Actions
              • Set bulletcreatepoint = (Position of (Triggering unit))
              • Set bulletcreatefacing = (Facing of (Triggering unit))
              • Set machinegunammo[(Player number of (Owner of (Triggering unit)))] = (machinegunammo[(Player number of (Owner of (Triggering unit)))] - 1)
              • Unit - Create 1 machinegun bullet for (Owner of (Triggering unit)) at bulletcreatepoint facing bulletcreatefacing degrees
              • Unit Group - Add (Last created unit) to bulletsinmap
              • Custom script: call RemoveLocation(udg_bulletcreatepoint)
              • Wait 0.10 seconds
        • Else - Actions
          • Set tmp_group = (Player group((Owner of (Triggering unit))))
          • Game - Display to tmp_group the text: |cffff0000Ammo is o...
          • Custom script: call DestroyForce(udg_tmp_group)


and when a bullet is created, it is moved with this trigger:

Trigger:
  • bullet move
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in bulletsinmap and do (Actions)
        • Loop - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Or - Any (Conditions) are true
                • Conditions
                  • (Unit-type of (Picked unit)) Equal to machinegun bullet
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • (Unit-type of (Picked unit)) Equal to machinegun bullet
                • Then - Actions
                  • Set bulletspeed = 30.00
                • Else - Actions
              • Set bulletposition = (Position of (Picked unit))
              • Set bulletfacing = (Facing of (Picked unit))
              • Set bulletmoveto = (bulletposition offset by bulletspeed towards bulletfacing degrees)
              • Unit - Move (Picked unit) instantly to bulletmoveto, facing bulletfacing degrees
              • Unit - Add a 8.00 second Generic expiration timer to (Last created unit)
              • Custom script: call RemoveLocation(udg_bulletposition)
              • Custom script: call RemoveLocation(udg_bulletmoveto)
            • Else - Actions


and since the bullets will move until it hits an enemy, or it enters the black area outside the playable map area, i created this trigger(to prevent fatal error that occurs when a unit enters that black area):
Trigger:
  • bulletproof
    • Events
      • Unit - A unit enters topside <gen>
      • Unit - A unit enters rightside <gen>
      • Unit - A unit enters leftside <gen>
      • Unit - A unit enters downside <gen>
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Unit-type of (Triggering unit)) Equal to machinegun bullet
    • Actions
      • Unit - Remove (Triggering unit) from the game


but the problem is, when i some bullets and then comes to the black area, theyre supposed to be removed, and they are removed, but then it starts to lag heavily, but just for some seconds, then it goes back to normal.(atleast it has something to do with the bullets)

can anyone figure out why this is happening?
 

Cookiemaster

New Member
Reaction score
36
First of,

Trigger:
  • Wait 0.10 seconds

Don't use waits for such things. They are inaccurate. Just remove them and create the units at different distances from the caster. (E.g. 60,80,100,120,140. The bullets will have 20 distance in between. But if you really want to spawn the bullets on intervals, look into timers and get a bit more knowledge of JASS.(Though JASS is not required. Just very recommended if you get into these things.))


Moving on, your bullet "Move" code. It needs some cleaning up to do.

What you do is for every unit in the bulletsinmap unit group, you check if it's a "machinegun bullet" unit. (This is okay if you're going to add other bullets later.)

But after that, you check if the picked unit is a "machinegun bullet" unit for the second time, and if that is true (which it will always be, since otherwise it would not reach these checks), it sets bulletspeed to 30.

A simple thing you could do is change this:
Trigger:
  • Set bulletmoveto = (bulletposition offset by bulletspeed towards bulletfacing degrees)

Into this:
Trigger:
  • Set bulletmoveto = (bulletposition offset by 30.00 towards bulletfacing degrees)

And then remove the "if machinegun = bullet then set bulletspeed = 30.00" altogether.


A third thing I would like to address about your triggers would be this:
Trigger:
  • Unit - Add a 8.00 second Generic expiration timer to (Last created unit)

Why do you do this every time the bullets gets moved? You could instead perform this action when you create the bullet, so that the game doesn't have to handle it every time it moves a bullet.
 

Wratox1

Member
Reaction score
22
First of,

Trigger:
  • Wait 0.10 seconds

Don't use waits for such things. They are inaccurate. Just remove them and create the units at different distances from the caster. (E.g. 60,80,100,120,140. The bullets will have 20 distance in between. But if you really want to spawn the bullets on intervals, look into timers and get a bit more knowledge of JASS.(Though JASS is not required. Just very recommended if you get into these things.))


Moving on, your bullet "Move" code. It needs some cleaning up to do.

What you do is for every unit in the bulletsinmap unit group, you check if it's a "machinegun bullet" unit. (This is okay if you're going to add other bullets later.)

But after that, you check if the picked unit is a "machinegun bullet" unit for the second time, and if that is true (which it will always be, since otherwise it would not reach these checks), it sets bulletspeed to 30.

A simple thing you could do is change this:
Trigger:
  • Set bulletmoveto = (bulletposition offset by bulletspeed towards bulletfacing degrees)

Into this:
Trigger:
  • Set bulletmoveto = (bulletposition offset by 30.00 towards bulletfacing degrees)

And then remove the "if machinegun = bullet then set bulletspeed = 30.00" altogether.


A third thing I would like to address about your triggers would be this:
Trigger:
  • Unit - Add a 8.00 second Generic expiration timer to (Last created unit)

Why do you do this every time the bullets gets moved? You could instead perform this action when you create the bullet, so that the game doesn't have to handle it every time it moves a bullet.

the wait is ok, since i use a custom integer with player index

yes, i am going to add other kind of bullets, and since not all bullets have the same speed i am doing this..

and about the expiration timer, i forgot about that:eek:, will move it to when its created asap!
 

Accname

2D-Graphics enthusiast
Reaction score
1,463
well, can this system cause lag? i'd say yeah because all periodic triggers can cause lag.

however, could that system cause lag spikes which come and go? naaah, i dont think so.

if you are really sure that these lags only sometimes appear and stay only for a little time i'd say its not because of this sytem. lag spikes are more likely to come together with loading object editor data. for example custom units with custom abilities being spawned for the very first time in the game. that could cause short little lag spikes.

if what you are saying is true i would rather look for something else as the cause of this.


well, just looked through your triggers, there are no memory leaks at all, and nothing which is downright wrong with this. its, maybe not perfect, but fine though.

one thing however i'd say should be changed if possible.
in the very first trigger, create the TempPoint variable before the loop and remove it after. because all of your bullets get spawned at the Position of the triggering unit. and since it will most probably not move in this short intervall of shooting, or maybe it couldnt even move because its shooting, you could just create 1 point variable for all of the bullets at once instead of creating and destroying as many points as you are shooting bullets.
 

Wratox1

Member
Reaction score
22
well, can this system cause lag? i'd say yeah because all periodic triggers can cause lag.

however, could that system cause lag spikes which come and go? naaah, i dont think so.

if you are really sure that these lags only sometimes appear and stay only for a little time i'd say its not because of this sytem. lag spikes are more likely to come together with loading object editor data. for example custom units with custom abilities being spawned for the very first time in the game. that could cause short little lag spikes.

if what you are saying is true i would rather look for something else as the cause of this.


well, just looked through your triggers, there are no memory leaks at all, and nothing which is downright wrong with this. its, maybe not perfect, but fine though.

one thing however i'd say should be changed if possible.
in the very first trigger, create the TempPoint variable before the loop and remove it after. because all of your bullets get spawned at the Position of the triggering unit. and since it will most probably not move in this short intervall of shooting, or maybe it couldnt even move because its shooting, you could just create 1 point variable for all of the bullets at once instead of creating and destroying as many points as you are shooting bullets.

im pretty sure that this system is whats causing the lags, since its only when i have fired some bullets these lags occurs, and doesnt have many more triggers than these that do something except for the beginning(at the moment), but there are my move triggers for my heroes however, i doubt they has something to do with this, but i can show you them anyway:
Trigger:
  • move
    • Events
      • Time - Every 0.03 seconds of game time
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 12, do (Actions)
        • Loop - Actions
          • Camera - Set (Player((Integer A)))'s camera Rotation to (Facing of ship[(Integer A)]) over 0.00 seconds
          • Camera - Set (Player((Integer A)))'s camera Angle of attack to -25.00 over 0.00 seconds
          • Camera - Set (Player((Integer A)))'s camera Distance to target to 2000.00 over 0.00 seconds
          • Camera - Set (Player((Integer A)))'s camera Height Offset to 150.00 over 0.00 seconds
          • Selection - Select ship[(Integer A)] for (Player((Integer A)))
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • forward[(Integer A)] Equal to True
              • shipspeed[(Integer A)] Less than or equal to ((Real((Intelligence of ship[(Integer A)] (Exclude bonuses)))) / 2.00)
            • Then - Actions
              • Set shipspeed[(Integer A)] = (shipspeed[(Integer A)] + 0.15)
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • shipspeed[(Integer A)] Greater than 0.00
                • Then - Actions
                  • Set shipspeed[(Integer A)] = (shipspeed[(Integer A)] - 0.05)
                • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • And - All (Conditions) are true
                • Conditions
                  • backward[(Integer A)] Equal to True
                  • shipspeed[(Integer A)] Greater than 0.00
            • Then - Actions
              • Set shipspeed[(Integer A)] = (shipspeed[(Integer A)] - 0.15)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • left[(Integer A)] Equal to True
              • shipangle[(Integer A)] Less than (((Real((Intelligence of ship[(Integer A)] (Exclude bonuses)))) / 5.00) x 2.00)
            • Then - Actions
              • Set shipangle[(Integer A)] = (shipangle[(Integer A)] + 0.50)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • right[(Integer A)] Equal to True
              • shipangle[(Integer A)] Greater than (((Real((Intelligence of ship[(Integer A)] (Exclude bonuses)))) / 5.00) x -2.00)
            • Then - Actions
              • Set shipangle[(Integer A)] = (shipangle[(Integer A)] - 0.50)
            • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • right[(Integer A)] Not equal to True
              • left[(Integer A)] Not equal to True
            • Then - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • shipangle[(Integer A)] Greater than 0.00
                • Then - Actions
                  • Set shipangle[(Integer A)] = (shipangle[(Integer A)] - 0.50)
                • Else - Actions
                  • Set shipangle[(Integer A)] = (shipangle[(Integer A)] + 0.50)
            • Else - Actions
          • Set shipposition = (Position of ship[(Integer A)])
          • Set shipfacing = (Facing of ship[(Integer A)])
          • Set shipmoveto = (shipposition offset by shipspeed[(Integer A)] towards (shipfacing + shipangle[(Integer A)]) degrees)
          • Unit - Move ship[(Integer A)] instantly to shipmoveto, facing (shipfacing + shipangle[(Integer A)]) degrees
          • Custom script: call RemoveLocation(udg_shipmoveto)
          • Custom script: call RemoveLocation(udg_shipposition)
          • Set shipfacing = 0.00


Trigger:
  • forward press
    • Events
      • Player - Player 1 (Red) Presses the Up Arrow key
      • Player - Player 2 (Blue) Presses the Up Arrow key
    • Conditions
      • (ship[(Player number of (Triggering player))] is alive) Equal to True
    • Actions
      • Set forward[(Player number of (Triggering player))] = True

i have similar triggers for all the arrowkeys, and for the release event..

Edit: actually, on my last testing, which i did after i moved the Generic expiration action to my create-trigger, it didnt lag at all, no matter how many bullets i fired, so i think that did it, and if it didnt i will tell you!

thanks for the help(if it helped)!
 
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

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top