Problem with code
by Larry Dolyniuk · in Game Design and Creative Issues · 07/05/2010 (11:19 am) · 6 replies
Hello, I have created a function to spawn 50 AI to 50 spawnpoints in my "battlefield", unfortunately my noobish way of doing things has led to increased memory consumption (my client gets extremely laggy) and lack of my AI players :p, each spawnpoint is named either GS1 - GS50 or BS1 - BS50 giving two sides to a battlefield.
as you can see I even tried setting each indexed string to null after I finished using them, but that did nothing haha, any help would be wonderful, sorry if this is too noobish of a problem, thanks :).
function spawn()
{
for(%i = 1; %i <= 50; %i++)
{
%Gq = "G" @ %i;
%Bq = "B" @ %i;
%GSpawn = "GS" @ %i;
%BSpawn = "BS" @ %i;
AIPlayer::spawn(%Gq, %GSpawn);
AIPlayer::spawn(%Bq, %BSpawn);
%Gq = null;
%Bq = null;
}
}as you can see I even tried setting each indexed string to null after I finished using them, but that did nothing haha, any help would be wonderful, sorry if this is too noobish of a problem, thanks :).
About the author
#2
07/05/2010 (5:34 pm)
%Gq = null; %Bq = null;I'm pretty sure this is incorrect syntax, but it's also redundant - %Gq and %Bq are only defined in the scope of the for loop itself, so they will be recreated each loop. (Same with %GSpawn and %BSpawn.) But even if not, you're overwriting their values each time, so it wouldn't matter if they did carry over ;).
Quote:and lack of my AI playersThey're not spawning? Can you spawn a single AIPlayer using the console by manually passing values to AIPlayer::spawn? Have you checked they're not all falling under the terrain or something? Or being spawned at the origin?
#3
if I can post youtube videos heres what it looks like, it is no longer laggy, just using this method
I feel like t3d should be able to handle large numbers, besides the abrupt stopping they do not slow down my performance at all. I think thats because they are still pretty low-poly models, it might be that the engine is looping between each taking a turn to move each forward but I really have no clue, if there is a fix that would be cool.
edit---
They run a lot smoother after a bunch of soldiers die :(
I guess there is nothing wrong with the method, and the problem is in fact numbers qq
07/05/2010 (8:50 pm)
I actually solved the problem using a resource a while ago, I should have updated here my status, but yes I am able to spawn AI's now unfortunately I have found another bump in the road :/ here is a video showing what problems I am having:if I can post youtube videos heres what it looks like, it is no longer laggy, just using this method
%G.setMoveDestination(%c.getTransform(), false );causes my soldiers to move forward, stop, move forward, stop etc. and it is really killing the cinematic part of my game :/
I feel like t3d should be able to handle large numbers, besides the abrupt stopping they do not slow down my performance at all. I think thats because they are still pretty low-poly models, it might be that the engine is looping between each taking a turn to move each forward but I really have no clue, if there is a fix that would be cool.
edit---
They run a lot smoother after a bunch of soldiers die :(
I guess there is nothing wrong with the method, and the problem is in fact numbers qq
#4
BTW, what is the text in the console window at the beginning of the video? It looks like it is throwing a bunch of errors?
07/06/2010 (10:50 am)
Are you calling %G.setMoveDestination(%c.getTransform(), false );in a loop? If so, you should try to slow your loop down. Maybe the code is being re-executed with the same position data over and over again or invalid position data. That would explain all the starts and stops your AI seems to be doing.
BTW, what is the text in the console window at the beginning of the video? It looks like it is throwing a bunch of errors?
#5
07/06/2010 (12:55 pm)
@Larry: Have you tried bumping up the network stats? Packet rates and such have an effect on lag- a big one. I suggest spending some time on that and figuring out where you can lighten the load in the network and general class code (the classes are sample implementations, of course, so they have features implemented that you might not need, yet take up bandwidth that you can save).
#6
Another thing is I also have 100 hidden static objects representing the location each AI will spawn, so if I create a remove function after they spawn maybe that would speed things up a bit
07/06/2010 (2:44 pm)
The errors in the console were what happens when my AI die from a previous simulation running, I hadn't implemented the isObject() into my code prior to capturing video, but that had nothing to do with my loops in the meantime, and I don't think that it is any loops causing it because setting the moveDestination to a marker without any loops running (for example my "fvf();" function which starts the battle) in the background still results in the choppy AI position updates, in editor mode I have found the bounding box moves to the location without any problems, its just my model that lags behind and seems to teleport to each location. Also I'll have to look into removing unnecessary class implementations, maybe that will make packets move faster :).Another thing is I also have 100 hidden static objects representing the location each AI will spawn, so if I create a remove function after they spawn maybe that would speed things up a bit
Torque Owner Alain Labrie
Ware-Wolf Games