client side coding snag Created 13 years ago2010-11-29 05:30:37 UTC by 2muchvideogames 2muchvideogames

Created 13 years ago2010-11-29 05:30:37 UTC by 2muchvideogames 2muchvideogames

Posted 13 years ago2010-11-29 05:39:31 UTC Post #287461
Ahhh, TWHL, I need help (again for the 100th time.)

Today I have this function here (DrawHudStringReverse). It involves redrawing the HUD when you pick up something or another.

[quote]// draws a string from right to left (right-aligned)
int CHud :: DrawHudStringReverse( int xpos, int ypos, int iMinX, char *szString, int r, int g, int b )
{
// find the end of the string
for ( char *szIt = szString; *szIt != 0; szIt++ )
{ // we should count the length?
}
[u][blue]char[/blue] *szIt;[green]// AMMO FAIL ? I put this in[/green][/u]
// iterate throug the string in reverse
for ( szIt--;  szIt != (szString-1);  szIt-- )
{
	int next = xpos - gHUD.m_scrinfo.charWidths[ *szIt ]; // variable-width fonts look cool
	if ( next < iMinX )
		return xpos;
	xpos = next;
	TextMessageDrawChar( xpos, ypos, *szIt, r, g, b );
}
return xpos;
}[/quote]

So the problem is this: By default, the line that is underlined above does not exist. However, running it straight on in 2008 express causes the problem "szIt is undeclared" to appear in the subsequent for loop. So I added the underlined line to maybe fix the problem. Guess what happens?

Every time I pick up ammo, instead of a number like (8 shells) my HUD shows a Japanese symbol or something. So if I pick up ammo_buckshot it displays (Japanese Symbol) shells. If I pick up handgrenades it says I got (Japanese Symbol) grenades. You get the idea.

Sooo... how to fix this?

(P.S. if you noticed there's an empty for loop. Weird crap like this appear often in the codebase and the comments show alot of valve's dissatisfaction with the code and using "sleazy" coding. Boo.)

(P.P.S. If drawing a right-aligned text is this difficult for them then Microsoft word would go out of business..)
Posted 13 years ago2010-11-29 19:45:11 UTC Post #287482
I think this should work:
[quote]
int CHud::DrawHudStringReverse( int xpos, int ypos, int iMinX, char *szString, int r, int g, int b )
{
char *szIt;
// find the end of the string
for( szIt = szString; *szIt != 0; szIt++ )
{ // we should count the length?
}
// iterate throug the string in reverse
for( szIt--;  szIt != (szString-1);  szIt-- )
{
	int next = xpos - gHUD.m_scrinfo.charWidths[ *szIt ]; // variable-width fonts look cool
	if( next < iMinX )
		return xpos;
	xpos = next;
	TextMessageDrawChar( xpos, ypos, *szIt, r, g, b );
}
return xpos;
}[/quote]
Posted 13 years ago2010-11-30 04:35:28 UTC Post #287489
thanks man! This worked.

I would ask for an explanation or something but chances are I prolly won't understand it. Now the client side is fully functional and coding weapons is possible. I already did the tfc shotgun but unfortunately I lack coding knowledge so sucks to be me. What can I say.
Posted 13 years ago2010-11-30 07:11:23 UTC Post #287493
No problem. I remember I had plenty of problems getting the code to work with Visual Studio 2008.
Also, the for loop is doing something (it's moving the pointer to the end of the string; for some reason Visual C++ 6's compiler makes for loop variables exist for the life of the function rather than just the loop). I don't think it's the most intuitive way of doing it either.
You must be logged in to post a response.