Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to "verify" your details, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.
 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ color code problems on swr

color code problems on swr

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Jason   (109 posts)  Bio
Date Thu 08 Feb 2007 04:19 PM (UTC)
Message
ok here is my problem first. I've made my own custom score sheet for my mud. but down in the language portion how it had to be set up is giving me a problem with the color. here is how it looks:

+------------------------------------+ | __)|      |      |(__ | |Your hands are not sterile.      |
|           LANGUAGES                | |___)|      |      |(___| |You feel great.                  |
+------------------------------------+      |      |      |      |You are in danger of dehydrating.|
|common wookiee twilek rodian        |      |      |      |      |You are starving to death.       |
|hutt mon calamari noghri        |      |      |      |      |                                 |<---- this line here.  Hutt is in red (cause that is what you are speaking)
|ewok gungan barabel bith            |      |      |      |      +---------------------------------+
|gamorrean trianii jawa adarian      |      |      |      |      |                                 |
|verpine defel trandoshan            |      |      |      |      +---------------------------------+
|chadra-fan quarren duinuogwuin      |      |      |      |      |       ORGANIZATION DATA         |
|toydarian zabrak falleen coynite    |      |      |      |      +---------------------------------+


BUT should look like this:

+------------------------------------+ | __)|      |      |(__ | |Your hands are not sterile.      |
|           LANGUAGES                | |___)|      |      |(___| |You feel great.                  |
+------------------------------------+      |      |      |      |You are in danger of dehydrating.|
|common wookiee twilek rodian        |      |      |      |      |You are starving to death.       |
|hutt mon calamari noghri            |      |      |      |      |                                 |
|ewok gungan barabel bith            |      |      |      |      +---------------------------------+
|gamorrean trianii jawa adarian      |      |      |      |      |                                 |
|verpine defel trandoshan            |      |      |      |      +---------------------------------+
|chadra-fan quarren duinuogwuin      |      |      |      |      |       ORGANIZATION DATA         |
|toydarian zabrak falleen coynite    |      |      |      |      +---------------------------------+
Top

Posted by Jason   (109 posts)  Bio
Date Reply #1 on Thu 08 Feb 2007 04:29 PM (UTC)
Message
ok notice the line is 4 spaces short than the rest at the language portion. now if i would change from the language hutt to the language common the hutt line will look fine... BUT the common line will be short.
Her is the code that controls what one is red (if any) I'll just past the two lines that deal with the common line and the hutt line

    strcpy(lbuf, "&B|");

    for (iLang = 0; lang_array[iLang] != LANG_UNKNOWN; iLang++)
    {
	sn = skill_lookup(lang_names[iLang]);

	if (sn < 0)
		continue;
	else if ((ch->pcdata->learned[sn] > 0 && !IS_IMMORTAL(ch)) || IS_IMMORTAL(ch))
	{	
		if ((strlen(lbuf) + strlen(lang_names[iLang])) >= 36)
		{
			lcnt = iLang;
			break;
		}
		if (ch->speaking & lang_array[iLang])
		{
			strcat(lbuf, "&R");
			strcat(lbuf, lang_names[iLang]);
			strcat(lbuf, "&B ");
		}
		else
		{
			strcat(lbuf, lang_names[iLang]);
			strcat(lbuf, " ");
		}
		continue;
	}
    }

    for (;;)
    {
	if (strlen(lbuf) != 39)
		strcat(lbuf, " ");
	else
		break;
    }

    if (!IS_NPC(ch) && ch->pcdata->condition[COND_FULL] == 0 && !IS_SET(ch->pcdata->cyber, CYBER_REACTOR))
	strcat(lbuf, "|&G      |      |      |      &B|&WYou are starving to death.       &B|\n\r");
    else
	strcat(lbuf, "|&G      |      |      |      &B|                                 |\n\r");

    send_to_char(lbuf, ch);

    strcpy(lbuf, "&B|");

    for (iLang = lcnt, lcnt = 0; lang_array[iLang] != LANG_UNKNOWN; iLang++)
    {
	sn = skill_lookup(lang_names[iLang]);

	if (sn < 0)
		continue;
	else if ((ch->pcdata->learned[sn] > 0 && !IS_IMMORTAL(ch)) || IS_IMMORTAL(ch))
	{	
		if ((strlen(lbuf) + strlen(lang_names[iLang])) >= 36)
		{
			lcnt = iLang;
			break;
		}
                if (ch->speaking & lang_array[iLang])
                {
                        strcat(lbuf, "&R");
                        strcat(lbuf, lang_names[iLang]);
                        strcat(lbuf, "&B ");
                }
                else
                {
                        strcat(lbuf, lang_names[iLang]);
                        strcat(lbuf, " ");  
                }		
		continue;
	}
    }

    for (;;)
    {
	if (strlen(lbuf) != 39)
		strcat(lbuf, " ");
	else
		break;
    }

    if (!IS_NPC(ch) && ch->pcdata->condition[COND_DRUNK] > 10)
	strcat(lbuf, "|&G      |      |      |      &B|&WYou are drunk.                   &B|\n\r");
    else
	strcat(lbuf, "|&G      |      |      |      &B|                                 |\n\r");

    send_to_char(lbuf, ch);
Top

Posted by Nick Gammon   Australia  (23,062 posts)  Bio   Forum Administrator
Date Reply #2 on Thu 08 Feb 2007 07:36 PM (UTC)
Message
Your "spoken" line is 4 characters short, and the codes to put it into a different colour are 4 characters: &R and &B.

So, you need to adjust the compensation for the width to allow for the fact that that line is 4 characters longer (well, 4 characters less in printable characters).

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Jason   (109 posts)  Bio
Date Reply #3 on Thu 08 Feb 2007 07:40 PM (UTC)
Message
Yeah i know this... i just can't figure out how with out the mud crashing LOL
Top

Posted by Zeno   USA  (2,871 posts)  Bio
Date Reply #4 on Sun 11 Feb 2007 07:17 PM (UTC)
Message
What are you doing to make it crash? Use gdb to report the backtrace here.

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
Top

Posted by Nick Gammon   Australia  (23,062 posts)  Bio   Forum Administrator
Date Reply #5 on Mon 12 Feb 2007 05:04 AM (UTC)
Message
It would help to post the code, as modified, that you say crashes. Also you can help yourself by checking out the loop inside gdb, as Zeno said, to do this see this article:

http://www.gammon.com.au/forum/?id=3653

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Jason   (109 posts)  Bio
Date Reply #6 on Tue 13 Feb 2007 10:47 PM (UTC)
Message
ok it no longer crashes i have made some progress and here is what i have

    strcpy(lbuf, "&B|");

    for (iLang = 0; lang_array[iLang] != LANG_UNKNOWN; iLang++)
    {
	sn = skill_lookup(lang_names[iLang]);

	if (sn < 0)
		continue;
	else if ((ch->pcdata->learned[sn] > 0 && !IS_IMMORTAL(ch)) || IS_IMMORTAL(ch))
	{	
		if ((strlen(lbuf) + strlen(lang_names[iLang])) >= 36)
		{
			lcnt = iLang;
			break;
		}
		if (ch->speaking & lang_array[iLang])
		{
			strcat(lbuf, "&R");
			strcat(lbuf, lang_names[iLang]);
			strcat(lbuf, "&B ");
		}
		else
		{
			strcat(lbuf, lang_names[iLang]);
			strcat(lbuf, " ");
		}
		continue;
	}
    }

    for (;;)
    {
	if (strlen(lbuf) != 39)
		strcat(lbuf, " ");
	else
		break;
    }

    if (!IS_NPC(ch) && ch->pcdata->condition[COND_FULL] == 0 && !IS_SET(ch->pcdata->cyber, CYBER_REACTOR))
	strcat(lbuf, "|&G      |      |      |      &B|&WYou are starving to death.       &B|\n\r");
    else
	strcat(lbuf, "|&G      |      |      |      &B|                                 |\n\r");

    send_to_char(lbuf, ch);

this is the original code and made the line look like this
Top

Posted by Jason   (109 posts)  Bio
Date Reply #7 on Tue 13 Feb 2007 10:48 PM (UTC)

Amended on Tue 13 Feb 2007 10:50 PM (UTC) by Jason

Message

+------------------------------------+ | __)|      |      |(__ | |Your hands are not sterile.      |
|           LANGUAGES                | |___)|      |      |(___| |You feel great.                  |
+------------------------------------+      |      |      |      |You are in danger of dehydrating.|
|common wookiee twilek rodian    |      |      |      |      |You are starving to death.       |<---- this line here.  common is in red (cause that is what you are speaking)
|hutt mon calamari noghri            |      |      |      |      |                                 |
|ewok gungan barabel bith            |      |      |      |      +---------------------------------+
|gamorrean trianii jawa adarian      |      |      |      |      |                                 |
|verpine defel trandoshan            |      |      |      |      +---------------------------------+
|chadra-fan quarren duinuogwuin      |      |      |      |      |       ORGANIZATION DATA         |
|toydarian zabrak falleen coynite    |      |      |      |      +---------------------------------+
Top

Posted by Jason   (109 posts)  Bio
Date Reply #8 on Tue 13 Feb 2007 10:52 PM (UTC)
Message
now i altered the code to look like this:

    strcpy(lbuf, "&B|");

    for (iLang = 0; lang_array[iLang] != LANG_UNKNOWN; iLang++)
    {
	sn = skill_lookup(lang_names[iLang]);

	if (sn < 0)
		continue;
	else if ((ch->pcdata->learned[sn] > 0 && !IS_IMMORTAL(ch)) || IS_IMMORTAL(ch))
	{	
		if ((strlen(lbuf) + strlen(lang_names[iLang])) >= 36)
		{
			lcnt = iLang;
			break;
		}
		if (ch->speaking & lang_array[iLang])
		{
			strcat(lbuf, "&R");
			strcat(lbuf, lang_names[iLang]);
			strcat(lbuf, "&B ");
		}
		else
		{
			strcat(lbuf, lang_names[iLang]);
			strcat(lbuf, " ");
		}
		continue;
	}
    }

    for (;;)
    {
	if (strlen(lbuf) != 43)
		strcat(lbuf, " ");
	else
		break;
    }

    if (!IS_NPC(ch) && ch->pcdata->condition[COND_FULL] == 0 && !IS_SET(ch->pcdata->cyber, CYBER_REACTOR))
	strcat(lbuf, "|&G      |      |      |      &B|&WYou are starving to death.       &B|\n\r");
    else
	strcat(lbuf, "|&G      |      |      |      &B|                                 |\n\r");

    send_to_char(lbuf, ch);

the line if( strlen(lbuf) !=39); was changed to 43 instead... that gave me the 4 spaces back. but now if i'm not speaking a lang on that line it moves 4 spaces forward. is there a way to get it to stop moving back and forth or is it a loss cause?
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #9 on Tue 13 Feb 2007 11:12 PM (UTC)
Message
The problem is that the extra &R and &B strings are adding 4 spaces to your string.

To fix this, just set a flag if the character is speaking something, and if so, add 4 to 43.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Jason   (109 posts)  Bio
Date Reply #10 on Tue 13 Feb 2007 11:22 PM (UTC)
Message
david my problem was before that it was set to 39... when i was speaking a lang on that like (common) it was 4 spaces to short... I added 4 to 39... got 43.... so now when i am speaking common that line is ok... but lets say i change to the hutt lang on the next line down... the common line is then 4 spaces to long cause i added the 4. so if i add 4 again it is going to be 4 spaces to long when speaking common and 8 spaces to long when speaking hutt.. so i don't see how that will help
Top

Posted by David Haley   USA  (3,881 posts)  Bio
Date Reply #11 on Tue 13 Feb 2007 11:37 PM (UTC)
Message
Then just count how many color codes you emitted and compensate accordingly by adding two to the length you pad to per color code.

I'm not saying to just add 4 spaces without thinking. I'm saying that you need compensate for the color codes, which contribute to the string length but are not in fact actually printed.

Stop and think about the problem on paper, that might help. Draw out the character arrays and see what happens.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
Top

Posted by Kerrias   (5 posts)  Bio
Date Reply #12 on Wed 30 May 2007 01:47 AM (UTC)
Message
just a question...but have you tried the set_char_color(b, AT_RED) thingy instead of using the color tags? Probably have, but i'm just trying to make myself look like I almost know what I"m talking about...which I don't, really...I can't get the set_char_color thingy to work worth a tinker's fit...but you'd probably have more luck with it than me.
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


30,571 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.