Open main menu
AGIWiki


Tutorials and Guides




AGI is a game engine which imposes significant memory and resource constraints on the game developer. Among these constraints are:

This article discusses ways of managing your resources to make the most of them, including tips for avoiding the dreaded out of memory error. As you might imagine, some of the tips in this article might contradict each other. When this happens, you will have to decide which of the two provides you with more advantages. This is called a "trade-off."

Managing memory

No one wants to see their game spit out an out of memory error, but when it happens, all is not necessarily lost. Very often, games are not making careful use of their resources. The good news is that you can often overcome memory exhaustion and get your game up and running again. The bad news is that this requires thought and work. The really bad news is that there are sometimes traps for the unwary that can cause a game to crash or otherwise misbehave. With the advice presented here (and perhaps some help from the message board, you should be able to overcome the challenges and get your game working the way you want it to.

There are no guarantees, of course. Some projects are simply too ambitious for AGI, but with that said, here are some tips for avoiding memory exhaustion.

Discard unused resources

If you don't need that view of ego falling into the dumpster any more (because ego has already fallen in), discard it! If you leave it in memory, it is occupying valuable space that could be used by something else. Be careful, though. Discarding resources that are being used by other objects can crash the game, and there are even more subtle bugs that can arise if you don't discard your resource in the exact reverse order that you loaded them. See Memory and Script for more details on that issue.

Be mindful of view sizes

When you load a view resource, the entire resource gets loaded into memory. It doesn't matter if you are using only one loop or even just one cel! If you find you are exhausting your memory, check for views that are being loaded in the room that have unused loops or cels in them. If you can move those parts out of that view, you can save a lot of memory.

Be concise

When you are printing a message to the screen, every single letter adds a byte to the total amount of memory that the logic resource is using. This means you can't write like a student who's been assigned a 5-page paper and only has 3 pages of content. You must cut the fat.

print("I do not know whether or not he will come.");
print("I didn't actually do that in reality.");

The above two print commands are wasting memory! They use far too many characters to say what they're trying to say. Compare to these far better versions:

print("I don't know whether he'll come.");
print("I didn't do that."); // OR
print("I didn't really do that.");

The sentence I don't know whether he'll come. is 10 bytes less memory than I do not know whether or not he will come. and it says the same thing. Similarly, I didn't do that. is 20 bytes less memory than I didn't actually do that in reality.

The last sentence I didn't really do that. brings up an important point: it only saves 13 bytes of memory over I didn't actually do that in reality.; however, the meaning of the sentence is slightly different than the meaning of I didn't do that. If you can avoid it, you shouldn't sacrifice saying what you mean to say for the sake of saving a few bytes. However, you should also avoid using verbose sentences to say something simple.

So, yes, good writing skills can help you avoid an out of memory error. Go figure.

Related links