Archived

This topic is now archived and is closed to further replies.

Programmer16

Game Text question

Recommended Posts

I was wondering if it was a bad idea to store text in an array, and then access access the array for display? Here's how I'm doing it at the moment:
char g_pMsgAreaTotal[50][256] = 
{
	{"Hello from the first index of g_pMsgArea."},
	{"Hello from the second index of g_pMsgArea."},
	{"Hello from the third index of g_pMsgArea."},
	{"Hello from the fourth index of g_pMsgArea."},
};

int g_iMsgAreaCurrentIndex = 0;
char g_pCurrentMsgArea[513];


Then when the user presses down, it increases g_iMsgAreaCurrentIndex, and if the user presses up it decreases it. Then I render it every frame like this:

   
strcpy(g_pCurrentMsgArea,g_pMsgAreaTotal[g_iMsgAreaCurrentIndex]);
			strcat(g_pCurrentMsgArea,"\n");
			strcat(g_pCurrentMsgArea,g_pMsgAreaTotal[g_iMsgAreaCurrentIndex + 1]);

			g_Engine.GetFont().Print(g_pCurrentMsgArea,0,576);
Then question is about the first source code. < 1/17/04>[edit]: Typo [edited by - Programmer16 on January 17, 2004 2:38:13 AM]

Share this post


Link to post
Share on other sites
The syntax of that last line suggests you''re working in C++, so I''d say you should be using one of the built-in string types to work with strings. Static char *''s like this are definitely workable, but you''ll probably save yourself headaches in the long run by working at a slightly higher level.

It also looks like you''re always outputting two consecutive messages from the array - or trying to. Not sure why you''d want that. Be sure to check your array indices, too.

Oh, and where''s that 576 coming from? You should *at least* declare a constant for it.

Share this post


Link to post
Share on other sites
Yes, I'm using C++.

quote:
It also looks like you're always outputting two consecutive messages from the array - or trying to. Not sure why you'd want that. Be sure to check your array indices, too.

This displays the last 2 messages that the user received, and it can stores upto 50. The user can scroll also back and forth through them. Right now I'm just trying to work out the bugs. The final code won't copy the strings every frame, just when it needs to be updated.

quote:
Oh, and where's that 576 coming from? You should *at least* declare a constant for it.

The backbuffer is 800x600, which means (using tiles of 32x32) that there are 25x18.75 tiles, so I round down, 18 * 32 = 576. Its not going to change, and I don't use it anywhere else (as of right now), so I didn't see a reason why to use a constant (I know, this isn't a good practice).

Thanks

[edited by - Programmer16 on January 17, 2004 3:12:58 AM]

Share this post


Link to post
Share on other sites