PDA

View Full Version : problem hud.size



sabixão
13th May 2014, 13:21
deleteClientHudTextElementbyName( hud_text_name )
{
if( isDefined( self.txt_hud ) && self.txt_hud.size > 0 )
{
for(i=0; i<self.txt_hud.size; i++ )
{
if( isDefined( self.txt_hud[i].name ) && self.txt_hud[i].name == hud_text_name )
{
self.txt_hud[i] destroy();
self.txt_hud[i].name = undefined;
}
}
}
}

the hud[i] is destroyed successfully but, the problem is that the self.txt_hud.size does not decrease and remains allocated in the memory of the server! :/
is there any way to reduce the self.txt_hud.size?

sabixão
13th May 2014, 13:22
createClientHudTextElement( hud_text_name, x, y, xAlign, yAlign, horzAlign, vertAlign, foreground, sort, alpha, color_r, color_g, color_b, size, text )
{
if( !isDefined( self.txt_hud ) ) self.txt_hud = [];

self deleteHudTextElementbyName( hud_text_name );

count = self.txt_hud.size;

self.txt_hud[count] = newClientHudElem( self );
self.txt_hud[count].name = hud_text_name;
self.txt_hud[count].x = x;
self.txt_hud[count].y = y;
self.txt_hud[count].alignX = xAlign;
self.txt_hud[count].alignY = yAlign;
self.txt_hud[count].horzAlign = horzAlign;
self.txt_hud[count].vertAlign = vertAlign;
self.txt_hud[count].foreground = foreground;
self.txt_hud[count].sort = sort;
self.txt_hud[count].color = ( color_r, color_g, color_b );
self.txt_hud[count].hideWhenInMenu = true;
self.txt_hud[count].alpha = alpha;
self.txt_hud[count].fontScale = size;
self.txt_hud[count].font = "default";
self.txt_hud[count] setText( text );
}

serthy
13th May 2014, 13:47
self.txt_hud[i] destroy();
self.txt_hud[i].name = undefined;
you destroy the hud[i] here, hud[i] is now undefined and size is decreased
however you set hud[i].name afterwards to undefined, therefore hud[i] is now more or less defined
(since it holds the undefined membervariable name)


self.txt_hud[i] destroy(); should do the trick, there is no need to set it to undefined

Tally
13th May 2014, 14:00
createClientHudTextElement( hud_text_name, x, y, xAlign, yAlign, horzAlign, vertAlign, foreground, sort, alpha, color_r, color_g, color_b, size, text )
{
if( !isDefined( self.txt_hud ) ) self.txt_hud = [];

self deleteHudTextElementbyName( hud_text_name );

count = self.txt_hud.size;

self.txt_hud[count] = newClientHudElem( self );
self.txt_hud[count].name = hud_text_name;
self.txt_hud[count].x = x;
self.txt_hud[count].y = y;
self.txt_hud[count].alignX = xAlign;
self.txt_hud[count].alignY = yAlign;
self.txt_hud[count].horzAlign = horzAlign;
self.txt_hud[count].vertAlign = vertAlign;
self.txt_hud[count].foreground = foreground;
self.txt_hud[count].sort = sort;
self.txt_hud[count].color = ( color_r, color_g, color_b );
self.txt_hud[count].hideWhenInMenu = true;
self.txt_hud[count].alpha = alpha;
self.txt_hud[count].fontScale = size;
self.txt_hud[count].font = "default";
self.txt_hud[count] setText( text );
}

That is my code. Please credit me for it.

Tally
13th May 2014, 14:08
self.txt_hud[i] destroy();
self.txt_hud[i].name = undefined;
you destroy the hud[i] here, hud[i] is now undefined and size is decreased
however you set hud[i].name afterwards to undefined, therefore hud[i] is now more or less defined
(since it holds the undefined membervariable name)


self.txt_hud[i] destroy(); should do the trick, there is no need to set it to undefined

That is my code he is using, and I have found through experience that you have to undefine self.txt_hud.name once you have removed the element.

Other than that, it works perfectly fine. There is no need to further reduce sizes.

sabixão
13th May 2014, 14:27
yes , is a TallyMod function() this is a beautiful shot to reduce many code line , this hud.size allocated in the memory of a server with many huds
would not be a problem?

RobsoN
13th May 2014, 14:49
BTW Tally is hud.hideWhenInMenu = true; built-in engine function?

Tally
13th May 2014, 16:29
BTW Tally is hud.hideWhenInMenu = true; built-in engine function?

The code method he posted was from one of my COD4 mods. It doesn't work in COD2.

Tally
13th May 2014, 16:31
yes , is a TallyMod function() this is a beautiful shot to reduce many code line , this hud.size allocated in the memory of a server with many huds
would not be a problem?

When all elements have been destroyed, and you use the method again, it resets the array:


if( !isDefined( self.txt_hud ) ) self.txt_hud = [];

So, no: it wont affect server memory.