02 Aug, 2009, boblinski wrote in the 1st comment:
Votes: 0
This spell is also called "looking glass" on some muds I've played.

Anyway it's cast on a char and that char gets an affect placed on them..

From then on.. that char sees things backwards names, desc's, says, emotes etc etc..

For example:
Boblinski says "Hello mudbytes!" would become: iksnilboB syas "olleH setybdum!"

Boblinski nods in agreement. would become: iksnilboB sdon ni tnemeerga.


Does anyone have any advice on where I should begin? I'm using QuickMUD!
02 Aug, 2009, Chris Bailey wrote in the 2nd comment:
Votes: 0
Well, I don't know anything about QuickMUD or what kind of string utilities you have at your disposal. But it would seem like if you just apply the flag you want to your player and put a check for the flag in whichever method you use to output text to your player…if they have the flag, reverse the string before it's sent out?
02 Aug, 2009, Chris Bailey wrote in the 3rd comment:
Votes: 0
Psuedo code follows?
def send_text_to(player,msg)
text_to_socket(player,(player.is_affected_by?(:perplex) ? msg.reverse : msg))
end
02 Aug, 2009, Hades_Kane wrote in the 4th comment:
Votes: 0
Chris Bailey said:
Psuedo code follows?
def send_text_to(player,msg)
text_to_socket(player,(player.is_affected_by?(:perplex) ? msg.reverse : msg))
end


Nothing I've seen in ROM would lead me to believe that there is a built in solution for this. He'll more than likely have to write a function specifically to be able to do this from scratch if he can't find someone to give him the code or find a snippet of code for it.
02 Aug, 2009, Guest wrote in the 5th comment:
Votes: 0
invert_string from AFKMud would work, don't know if it would be difficult to port to Rom though. And it inverts the entire string, not each word in it.
02 Aug, 2009, Chris Bailey wrote in the 6th comment:
Votes: 0
It should be extremely simple to port, they are both in C right? And basically the same thing? I would hope that inverting the string, character by character would suffice…It will have the same end result. =)
02 Aug, 2009, Hades_Kane wrote in the 7th comment:
Votes: 0
I poked around a little bit in AFK MUD trying to find it to see if what I'm familiar with seemed like it would be easy enough… but I didn't look hard enough ;p
02 Aug, 2009, Chris Bailey wrote in the 8th comment:
Votes: 0
Well, if C doesn't have a built in utility to reverse a string… couldnt you just do something like…. Push each character from the original string into an array, then dump the contents of the array into a new string?
02 Aug, 2009, Guest wrote in the 9th comment:
Votes: 0
Well I went looking for it in our old C release but couldn't find it. Too lazy to unpack it somewhere where I can get at grep, so here's the C++ version:
string invert_string( const string & orig )
{
string result = "";
size_t j = 0;

if( orig.empty( ) )
return orig;

for( size_t i = orig.length( ) - 1; j < orig.length( ); –i, ++j )
result += orig[i];

return result;
}


And before anyone mentions it, yes, this is likely an uber messy way to do it. But works.
02 Aug, 2009, Hades_Kane wrote in the 10th comment:
Votes: 0
As long as he's compiling with something that handles c++, there should be no inherit problem in using a c++ function, right?
02 Aug, 2009, Chris Bailey wrote in the 11th comment:
Votes: 0
Not that I am aware of HK
02 Aug, 2009, Guest wrote in the 12th comment:
Votes: 0
Well there would be if what he sends to be inverted isn't already a std::string because that's all the function will touch :)

No wonder I couldn't find it - name got changed:
void invert( char *arg1, char *arg2 )
{
int i = 0;
int len = strlen( arg1 ) - 1;

while( i <= len )
{
*( arg2 + i ) = *( arg1 + ( len - i ) );
i++;
}
*( arg2 + i ) = '\0';
}


Even uglier I'm sure, but that does work in a C environment.
02 Aug, 2009, Hades_Kane wrote in the 13th comment:
Votes: 0
I might add that in just for the hell of it :p

Any credit I need to give or anything?
02 Aug, 2009, Guest wrote in the 14th comment:
Votes: 0
No credit needed, we got it from our old MUD but they didn't care either and now I don't remember who actually wrote it.

I look at that C code knowing exactly what it produces but still can't make sense of it. I've always hated C strings :)
02 Aug, 2009, Hades_Kane wrote in the 15th comment:
Votes: 0
I don't know if I don't have it implemented properly, but this is what I am getting:

say I am testing this to see what is going on.

You say '.no gniog si tahw eessee what is going on.'


It's kind of working?

Rather than trying to invert what everyone is seeing, I'm just toying with it right now and making a certain spell affect make you speak backwards.
02 Aug, 2009, Tonitrus wrote in the 16th comment:
Votes: 0
Samson said:
I look at that C code knowing exactly what it produces but still can't make sense of it. I've always hated C strings :)


Length is equal to the length of arg1 minus the terminating null char, then it's copied back to front. The reason it looks so ugly is because it doesn't use array notation. With array notation it'd be something like:

void invert( char *arg1, char *arg2 )
{
int i = 0;
int len = strlen( arg1 ) - 1;
while( i <= len )
{
arg2[i] = arg1[len - i];
arg2[i] = '\0';
}
}


which is a lot more readable.
02 Aug, 2009, Guest wrote in the 17th comment:
Votes: 0
Yeah, that's much easier to read, and makes more sense. You've got a bug in the rewrite though. Where you have
arg2[i] = '\0'
shouldn't that be an i++ and the terminating null be added after the while loop?
02 Aug, 2009, Hades_Kane wrote in the 18th comment:
Votes: 0
Ok, I have it figured out.

And yeah, his code made my MUD freeze, lol :p
02 Aug, 2009, Chris Bailey wrote in the 19th comment:
Votes: 0
Ported to Ruby, incase anyone needs it.

irb(main):018:0> "Hello World In Reverse!".reverse
=> "!esreveR nI dlroW olleH"
02 Aug, 2009, Hades_Kane wrote in the 20th comment:
Votes: 0
I think that with a bit of hacking into write_to_buffer it would be easy enough to get this working as the OP wanted. I toyed with it, and as long as I had color off, it seemed fine (although one weird thing was if I had a line that began and ended with ( and ) or [ and ] those weren't being reversed right), but in order to make it really work well, you'd have to incorporate checking for your color codes and make those reverse properly. I thought about trying to make that work, which I'm sure I could eventually, I'm just not that good with string manipulation and it'd be more effort for me than it was worth since I don't anticipate actually using this more than just a toy :p

If someone else put something up solving the color code issue, that'd be cool though.
0.0/89