In Tier 2, it is up to you to clear the memory allocated by the agk::Str command. It does not get cleared automatically when the variable goes out of scope. This will cause a memory leak.
You need to do use 'delete[] varname' to properly clean up memory allocated by agk::String.
Also, it is a good idea to move your variable definitions ('LPSTR j = agk::Str(h);') outside of the loops. It will take up less memory and be faster processing. Declare the variables before the loop and then just assign them within the loop.
And, the following code shows you how to avoid dealing with all of these issues using sprintf.
char filnam[256];
agk::SetFolder("");
agk::SetFolder("terrain");
if(!terrain_start)
{
agk::Message("here we go");
terrain_start = true;
for(int h=0; h <= 5; h++)
{
for(int g=0; g <= 5; g++)
{
sprintf(filnam,"terrain_x%dy%d.obj",h,g);
agk::Message("perfect");
if(agk::GetFileExists(filnam)==1)
{
obj++;
agk::LoadObject(obj,filnam);
agk::Message("got it!");
agk::SetObjectPosition(obj,0+1024*h,100,0+1024*g);
}
}
}
}
agk::SetFolder("");
agk::SetFolder("media");
Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master