Gw Temp


Tutorial - 'Reducing lag in your Game' by voxvam

An item about RPGMaker 2000 posted on


A tutorial on how to reduce lag in your game.


-----Reducing Game Lag-----
Here are some common sense tips to reducing lag in your rm2k game, or as I refer to as "Parallel Hell".
Parallel Hell is caused by the bad use of parallel events, cycles, autostart events, and label commands used to simulate cycles (which I will refer to in general as "looping events").

-----That's Nice, What's The Difference-----
Below I'll state my personal view/opinion/recommendation of when to use each of these looping events.

- Autostart: An autostart event should be run when the map is first loaded and only once. It should not loop at all, even though some people use it for such purposes.
- Parallel: A parallel event should be used for running multiple times only.
- Cycle: Used for the standard looping of certain pieces of code.
- Label: Labels actually can be used for any sort of looping structrure described above, however I recommend that you refrain from using them whenever possible. This will promote what some programmers refer to as structured coding (A little more code, but easier to read and modify) and give you exercise using the above looping events the way I believe they should be used.

-----Good Related Programming Practices-----
- All common parallel and autostart events should require a unique switch for the code to run.
- All map parallel and autostart events should require at least one event condition, preferably a unique switch.
- For every map parallel event, you should have an map autostart event for it.
- Be extra careful about setting variables and switches in parallel events, cycles, and labels as sometimes you only want to set the variable or switch once and not multiple times.
- If you want to set a variable or switch once, and use it in a parallel event, cycle, or label you are best to use an autostart event for just that purpose.
- A wait event command of at least 0.0 seconds should be in every looping event.
- Please, use some comments to split up important sections of code and to describe what you are trying to do.

-----The Three Simple Questions-----
Whenever using any sort of looping event, especially parallel events, ask yourself these three questions:
- What events are currently running and what events do I want to have running currently?
- How many times do I want this code to loop, or when do I want this code to stop looping?
- What code in this looping event actually needs to be here, and what code does not belong here?

-----The Three Simple Answers-----
- The only events that should be currently running are the ones you need to have running. One extra is one too many.
- Don't make the code loop any more times than you want it to.
- The only code that should be in a looping event is code that needs to be there, remove everything else (except comments of course) and put it somewhere outside of the loop (like another event).

-----The Three Simple Examples-----
- Remember how I said that you should use a unique switch as an event condition for all parallel and autostart events? That's how you can turn on or off the events you wish to.
- If you want the code to loop only five times, use a variable to count which loop you are on, and a fork condition to turn off the unique switch of that event when that counting variable equals five. If you want the code to loop every ten seconds, whynot use a wait of 10.0 seconds at the top of the event.
- A good place for code that doesn't belong in the looping event is another event page or an autostart condition.

-----I Have Code That I Want Looping, Not Always, But Still In The Loop-----
Well there are three styles I can think of when thinking about this:
- You want the code to run X number of times.
- You want the code to run every other time.
- You want the code to run until something happens.

-----Ways Around These Problems-----
For each way I have a similar solution. It's using what I call a "Self-Closing Fork". What I mean by a self-closing fork is a fork condition in which the condition of weather it will run or not is modified inside the fork condition itself (there is code in the fork that affects if that code will run again on the next loop or not).
- If you want the code to run X number of times, use a method similar to the above example with code that loops only five times.
- If you want the code to run every other time, use a similar method except instead of using a variable, use a switch and and just turn that switch on or off (using the Change Switch ON/OFF Trigger) on each loop.
- If you want the code to run until something happens, just using a simple fork condition with a switch in the loop will work. Once you change the switch to off (or on, depending how you coded it) that code will not (or will, depending on your logic) run again in the loop until the switch is changed back to what it was.

-----Common Troubleshooting Tips-----
- Make sure nothing loops forever (every cycle should have a break cycle, event autostart event should stop at some point).
- As stated before, be wary of setting variables and switches inside of looping events.
- Make sure to check the event start condition for all event pages and common events for looping event type start conditions like parallel and autostart (yes, even blank events as well).
- Be wary of looping events that call other looping events, as the wait times can and do tend to add up rather quickly.
- If you have looping events that call other looping events, the called looping events should almost always have the smaller wait time (as there are very few cases where the opposite is better).
- The wait for all looping events should never exceed 0.2 seconds (except for extreme cases) or unless you want that event to run every X seconds.
- Always try to find ways of making your code run faster, less code doesn't always mean quicker code. Like my square root algorithm, it is more code but it runs faster then the method using less code.
- A knowledge of which looping events are calling others, and which common events are being called by others can help.
- Planning out your algorithms can help reduce mistakes.
- Use comments for more than just "I coded this, this is my site" kind of stuff, they are there to help you and others understand what you are trying to do.
- Always test your code in stages, and multiple times to make sure things are working at the moment. That way you won't have small mistakes that turn into big ones (like NASA mixing up feet and meters with that mars probe incident).
- The number of pictures being used currently can affect the game's lag.
- The number of event pages for events on the current map can affect the game's lag.
- Beware of show picture commands as I hear they can be trouble inside of looping events.
- And the most common cause of game lag, the computer resources you have availiable while running the game can drastically affect the game's lag. That includes how fast your computer is, how much RAM you have, what else do you have running, if you are running in full screen or in test mode, if you are running from the exe file, and how long it has been since your last computer reboot.

-----Small Comment-----
This is actually a second version of this tutorial. If for some reason you had a hard time understanding this one, please try the first version at rpg2knet. You never know, you might understand that one better.

If you have a comment/question/suggestion, please feel free to email me at or catch me on aim (signon-name: voxvam).