Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, 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.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ SMAUG
➜ SMAUG coding
➜ Echo.. echo... echo?!
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Frobozz
(75 posts) 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?
| Top |
|
Posted by
| Zeno
USA (2,871 posts) 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 | Top |
|
Posted by
| Ithildin
USA (262 posts) 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.
| Top |
|
Posted by
| Greven
Canada (835 posts) 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 | Top |
|
Posted by
| David Haley
USA (3,881 posts) 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 | Top |
|
Posted by
| Greven
Canada (835 posts) 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 | Top |
|
Posted by
| Dave
Australia (93 posts) 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. | 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.
20,887 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top