# Working with text.

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

lol, I'm really kicking myself over this one. I'm writing a channel display and I cannot get my text to align properly. Here is what it looks like... When the server speaks to the client, it sends message (Max 200 char) to the client, which the client has to break into smaller messages that fit in each display row with set amount of characters. eg... A channel is composed of about 100 rows, where each row is drawn individually from all the others. Each row holds flag_FCharacters number of characters.
/* This procedure appends the message on the channel. */
void sDealWithMessage (char lcChannel, struct gtRGB loColor, char *lacMessage)
{
struct gtChannelRow *laoChannel;
int liX, liLength, liOffset, liShifter;

/* Get which channel we are appending to. */
if(lcChannel == flag_ChnDefault)
laoChannel = gaoChannelDefault;
else if(lcChannel == flag_ChnGamechat)
laoChannel = gaoChannelGamechat;

/* Append the message onto the given channel. */
for(liX=0;liX<100;liX++)
{
if(laoChannel[liX].lucUsed == 0)
{
lblFill:
/* We need to continously post until all of the message is gone. */
liLength = strlen(lacMessage);
liOffset = 0;
while(liLength > 0)
{
/* If its the first line, no padding. */
if(liOffset == 0)
{
laoChannel[liX].lucUsed = 1;
laoChannel[liX].loColor = loColor;
for(liShifter = 0; liShifter < 10; liShifter++)
if(lacMessage[flag_FCharacters - liShifter-1] == ' ' ||
lacMessage[flag_FCharacters - liShifter-1] == 0)
break;
strncpy(laoChannel[liX].lacMessage, &lacMessage[0], flag_FCharacters - liShifter);
liLength -= (flag_FCharacters - liShifter);
liOffset += (flag_FCharacters - liShifter);
liX++;
}
/* If this text took up multiple lines, than pad! */
else
{
strcpy(laoChannel[liX].lacMessage, "     ");
laoChannel[liX].lucUsed = 1;
laoChannel[liX].loColor = loColor;
for(liShifter = 0; liShifter < 10; liShifter++)
if(lacMessage[liOffset + flag_FCharacters - liShifter-1] == ' ' ||
lacMessage[liOffset + flag_FCharacters - liShifter-1] == 0)
break;
strncpy(&laoChannel[liX].lacMessage[5], &lacMessage[liOffset], flag_FCharacters - 5 - liShifter);
liLength -= flag_FCharacters - 5 - liShifter;
liOffset += flag_FCharacters - 5 - liShifter;
liX++;
}
}
break;
}
if(liX >= 89)
{
/* If we are approaching the end, memmove the bottom up. */
memset(&laoChannel[0], 0, sizeof(struct gtChannelRow) * 10);
memmove(&laoChannel[0],&laoChannel[10], 89*sizeof(struct gtChannelRow));
goto lblFill;
}

}
}


The problem is that, every line after the second isn't separating the edges properly, as shown in the screenshot. What am I doing wrong? [bawling]

##### Share on other sites
Thevein,

After a quick look at your code I suspect the problem is when you're trying to find the 'shifter' for your second and subsequent lines. I believe you scan backwards from (index) flag_FCharacters-1 to flag_FCharacters-10 looking to break the line, however in this case you've already used the first 5 characters (as your padding). This means you only have flag_FCharacters-5 characters for use in the line, therefore start and end your scan in the wrong place.

Cheers,

Tom

// Originalif(lacMessage[liOffset + flag_FCharacters - liShifter-1] == ' ' ||   lacMessage[liOffset + flag_FCharacters - liShifter-1] == 0)// Adjusted for paddingif(lacMessage[liOffset + (flag_FCharacters-5) - liShifter-1] == ' ' ||   lacMessage[liOffset + (flag_FCharacters-5) - liShifter-1] == 0)

##### Share on other sites
I cannot give any advice, but I like the layout of your game! Nice'n'tidy...

##### Share on other sites
Quote:
 Original post by TomHAfter a quick look at your code I suspect the problem is when you're trying to find the 'shifter' for your second and subsequent lines. I believe you scan backwards from (index) flag_FCharacters-1 to flag_FCharacters-10 looking to break the line, however in this case you've already used the first 5 characters (as your padding). This means you only have flag_FCharacters-5 characters for use in the line, therefore start and end your scan in the wrong place.

You solved it! [wow]

Many many thanks: I wish I could give you more ratings than just a mere 8, since you clearly deserve more. [smile]

See you all in a few weeks when I make post asking why my Firefields arn't burning the objects as they are suppose to.. (Just kidding of course)[rolleyes]

1. 1
Rutin
41
2. 2
3. 3
4. 4
5. 5

• 16
• 18
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633362
• Total Posts
3011526
• ### Who's Online (See full list)

There are no registered users currently online

×