ID:172781
 
Seemed simple at first, but I've tried many times to create a proc that would take a text string, flip it around (IE, "Hello BYOND!" would end up "!DNOYB olleH") and then display it however I choose, but I've failed miserably many times and my coding is so messed up that I'm not even gonna post it. Could anyone educate me on how to perform this?
Enigmaster2002 wrote:
Seemed simple at first, but I've tried many times to create a proc that would take a text string, flip it around (IE, "Hello BYOND!" would end up "!DNOYB olleH") and then display it however I choose, but I've failed miserably many times and my coding is so messed up that I'm not even gonna post it. Could anyone educate me on how to perform this?

I have just been toying around with this, and i havent really checked this, but this is what i came up with (i know its very unoptimised, but i just threw this together)
mob/verb/switchtext(T as text)
usr << T // outputting the message before-hand
var/z[length(T)] // make a new list that is the length of the text
var/c = 1
for(var/x = length(T), x > 0, x--) // populate the list backwards with the text message
z[x] = copytext(T,c,c+1)
c++
var/v
for(var/x = 1, x < length(T)+1, x++)
v += z[x] // a text string that has the original message backwards
usr << v // output the final message to the verb user
In response to Lazyboy
Eeek. No need to use lists! =)

A much simpler and faster version:

<code>proc/reversetext(txt as text) var/reversed="" for (var/X=length(txt); X>=1; X--) reversed+=copytext(txt,X,X+1) return reversed</code>
In response to Crispy
Crispy wrote:
Eeek. No need to use lists! =)

Too much c++ for me i think. Plus its been a long day and i couldnt be bothered thinking too much.
In response to Crispy
Now, I hate to bother, but I see the code, I know it works, but I haven't the faintest idea why. Most specifically, that for() statement. Mind explaining it?