[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Echo.. echo... echo?!

Echo.. echo... echo?!

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


Posted by Frobozz   (75 posts)  [Biography] bio
Date Thu 18 Nov 2004 05:48 AM (UTC)
Message
Goal:

Be able to echo to the mud more than one string of text at a time using the do_echo command.

Problem:

No idea how to either allow multiple lines of input OR
add on something like a text editor, similar to the one used in describe or redit desc.

Solution?

[Go to top] top

Posted by Zeno   USA  (2,871 posts)  [Biography] bio
Date Reply #1 on Thu 18 Nov 2004 03:21 PM (UTC)
Message
I'm not sure what you mean. Can you provide an example? If you want to echo multiple lines, just call the do_echo function multiple times in the same function, one after another. For example...

do_echo( ch, "line 1" );
do_echo( ch, "line 2" );

Zeno McDohl,
Owner of Bleached InuYasha Galaxy
http://www.biyg.org
[Go to top] top

Posted by Ithildin   USA  (262 posts)  [Biography] bio
Date Reply #2 on Thu 18 Nov 2004 07:04 PM (UTC)
Message
I know this is a cheesy way around it, but you could make a new command like do_decho and make it have howevery many arguments you want it to have. EG:

send_to_char( arg1 )
send_to_char (arg2)
so on and so on...so it'd be like...

decho "whatever" "whatever2" and it would show up like

whatever
whatever2

i know that's flawed, but it's general idea.

[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #3 on Thu 18 Nov 2004 10:33 PM (UTC)
Message
You could copy do_bio, modify it to to be appropriate, and then have it send as the string argument to do_echo the return of the copy_buffer.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by David Haley   USA  (3,881 posts)  [Biography] bio
Date Reply #4 on Thu 18 Nov 2004 11:02 PM (UTC)
Message
Don't forget to free the string and all that appropriately, else you'll be leaking little droplets of memory every time you use the function.

Or, if the lines are simple enough, you could just be using \n markers in the string and parse out "\n" to be an actual newline character.

e.g.

multiecho Hello there!\nThis is on a new line.\nAnd this is on the third line.

would print -->

Hello there!
This is one a new line.
And this is on the third line.

It's a pretty straightforward parsing algorithm to go through and replace literal "\n" with a newline. It's only slightly more complex if you want to be able to have literal \n in your output, in which case you would use an escape system e.g. "\\n" translations to "\n", not a newline.

David Haley aka Ksilyan
Head Programmer,
Legends of the Darkstone

http://david.the-haleys.org
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #5 on Fri 19 Nov 2004 06:17 AM (UTC)

Amended on Sat 20 Nov 2004 07:21 PM (UTC) by Greven

Message
Quite true, I guess I shouldn't assume everyone knows for copy_buffer works.

What you want is probably something like this to go with what Ksilyan suggested:
char * convert_newline(char *str)
{
        static char ret[MAX_STRING_LENGTH];
        char     *retptr;

        retptr = ret;
        for (; *str != '\0'; str++)
        {
            if (*str == '\\')
            {
                if ( *(str-1) == '\\' )
                    continue;
                else if ( *(str+1) == 'n' )
                {
                    *retptr = '\n';
                    retptr++;
                    str++;
                    continue;
                }
            }
            *retptr = *str;
            retptr++;
        }
        *retptr = '\0';
        return ret;
}


Then all you have to do is modify do_echo like this:
        echo_to_all(color, convert_newline(argument), target);
This is what you would see:

echo testmore
testmore

echo test\nmore
test
more

echo test\\nmore
test\nmore

Hope that helps

[EDIT] I modified this slightly, this will be a little more effeicent.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Dave   Australia  (93 posts)  [Biography] bio
Date Reply #6 on Sun 21 Nov 2004 01:04 PM (UTC)

Amended on Sun 21 Nov 2004 01:06 PM (UTC) by Dave

Message
if ( *(str-1) == '\\' )

If str hasn't been increased yet (ie. you're at the start of the string), then str - 1 would point to no-man's land. Might want to fix that.
[Go to top] 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.


18,662 views.

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

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

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

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]