• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How to Reduce game play lag

Level 17
Joined
Jun 17, 2007
Messages
1,433
How to Reduce game play lag

By hvo-busterkomo


1. Give variables initial values instead of setting them in a trigger.

Bad:
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Var[1] = 1
      • Set Var[2] = 1
      • Set Var[3] = 1
      • Set Var[4] = 1
      • Set Var[5] = 1
      • Set Var[6] = 1
      • Set Var[7] = 1
Mediocre:
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • For each (Integer A) from 1 to 7, do (Actions)
        • Loop - Actions
          • Set Var[(Integer A)] = 1
Good:

2. Avoid using variables when unnecessary

Bad:
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Random = (Random integer number between 1 and 2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Random Equal to 1
        • Then - Actions
          • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
        • Else - Actions
          • Unit - Create 2 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
Mediocre:
  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Random integer number between 1 and 2) Equal to 1
        • Then - Actions
          • Unit - Create 1 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
        • Else - Actions
          • Unit - Create 2 Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
Good:

  • Events
    • Map initialization
    • Conditions
    • Actions
      • Unit - Create (Random integer number between 1 and 2) Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees

3. Only use 1 Initialization trigger

Bad:


  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Var[1] = 1
  • Melee Initialization Copy
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Var[2] = 1
  • Melee Initialization Copy 2
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Var[3] = 1
Good:

  • Melee Initialization
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Set Var[1] = 1
      • Set Var[2] = 1
      • Set Var[3] = 1
4. Avoid small periodic checks

Bad:

  • Events
    • Time - Every 0.01 seconds of game time
    • Conditions
      • (Peasant 0000 <gen> is alive) Equal to False
    • Actions
      • Set Random = 1
That trigger will check 100 times a second!

Good:

  • Events
    • Time - Every 0.03 seconds of game time
    • Conditions
      • (Peasant 0000 <gen> is alive) Equal to False
    • Actions
      • Set Random = 1




5. Miscellaneous Tips

Avoid the
  • Do Nothing
action, it does what it says; nothing.
Also. Be sure to clean all Memory Leaks http://www.hiveworkshop.com/forums/showthread.php?t=35124

Note: This tutorial is incomplete
 
Last edited:
Level 40
Joined
Dec 14, 2005
Messages
10,532
1. Give variables initial values instead of setting them in a trigger.
That completely depends on the situation in which they're used =/

2. Avoid using variables when unnecessary
This is worded kind've badly; it sounds like you're advocating using Triggering Unit 10x instead of setting it to a variable then using the variable.

3. Only use 1 Initialization trigger
That doesn't really reduce lag, but it helps with the script size.

4. Avoid small periodic checks
That's really situational; a .01 second check and a .5 second check would be used in completely different circumstances.

You could mention that .03 is as smooth as .01 for sliding, etc, purposes.


As for your specific examples;

  1. the "Bad" way is faster than the "Mediocre" way, it just takes a little longer to write.
  2. that's a pretty good example, but you leak, BTW :p
  3. see the comments above.
  4. as said above, those aren't really comparable.
  5. no complaints.
 
It seems that you copied the information from other tutorials and that somehow you added to it some of your personal experience ...

You still have a lot of work to do ...

Also, sometimes 0.01 checks are necessary, example for a knockback ability, if you want to create a nice smooth effect for eye kandy, 0.01 timers are the solution.

About the variables, you should introduce people to local variables.
Also, you leak, and leaks decrease game speed.... Please comment the leaks or suggest a tutorial regarding them ..

Agree 99,9% with PurplePoot.
 
Lol, PP is correct, you can replace the If statement. Just use the condition and the actions normally. To increase a game speed, Sometimes avoiding ifs is a good idea (depending on the case), you should give a more correct example.

Also, To greatly increase game speed, you should talk about JASS and give people an introduction about BJ's, natives and some JASS basics.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
Lol, PP is correct, you can replace the If statement. Just use the condition and the actions normally. To increase a game speed, Sometimes avoiding ifs is a good idea (depending on the case), you should give a more correct example.

Also, To greatly increase game speed, you should talk about JASS and give people an introduction about BJ's, natives and some JASS basics.

it's even worse. In his specific example you could simply do
  • Unit - Create (random number between 1 and 2) Footman for Player 1 (Red) at (Center of (Playable map area)) facing Default building facing degrees
 
Eleandor said:
it's even worse. In his specific example you could simply do

It is NOT worse. Sometimes it can be much better. As i said, it DEPENDS on the case.

Also, we could use your trigger, but most people who are newbs wouldn't probably understand what it does ... and i believe tutorials are ment to all .... includind newbies.
 
Level 21
Joined
Aug 21, 2005
Messages
3,699
EDIT: Bah, stop calling me elenai dudes

I meant to say: Purplepoots suggestion indeed is better, but in this example even that suggestion could be done better.

IMO, reducing lag just depends too much on the specific case. All you can do is offer some clever mechanics on how to trigger things efficient, but I feel that to do so, you'll have to use better examples.
Since lag depends on each different case, I feel that using examples (especially ones like these that could be done without an if/then/else at all - whether it be in the condition or action part of a trigger) is not a very good idea. I think I'd learn more if you really told what happens when the trigger is executed and why its performance would be bad instead of just posting a few completely random examples and its "corrections"...

for example: point 1. It'd be better to explain what happens inside a loop so newbies understand why looping could perform slightly worse.
Above that, it'd be good to show pro's and cons. Loops can be useful, and I'd even use one when I have to set Var[1 to 7] to a constant number, since it's more work for a little bit more performance.
Something else that could be said about point 1: initial values can be set at the variablelist itself, which is even better than putting it in a trigger.

That's what I mean. It's better to explain the mechanics of certain actions in order to understand them than to give specific examples...
They might help to make something clear though, but then use a better example ;)

But I feel like I'm being to harsh to this tutorial, so I'll just wish you good luck improving it :)
 
Top