mIRC Homepage

Reversing Text Script

Posted By: 2big

Reversing Text Script - 28/08/03 01:16 AM

Well, I've been trying very hard to figure out how to reverse the text someone says using the on *:text: command, along with tokens, text identifiers, etc.

But I still can't seem to figure it out. What I mean is, I'm trying to write a script to reverse what anybody says. Anyway, any help would be appreciated. Thanks in advance.

Example of what I'm talking about:

<JohnSmith> Hey guys, how are you
<ReverserScript> uoy era woh ,syug yeH
Posted By: pheonix

Re: Reversing Text Script - 28/08/03 01:23 AM

Code:
alias reverse {
  var %x,%i = $len($1-)
  while (%i) {
    %x = %x $+ $replace($mid($1-,%i,1),$chr(32),_)
    dec %i
  }
  return $replace(%x,_,$chr(32))
}

//echo -a $reverse(text)
however that will strip comma's(",") frown
Posted By: 2big

Re: Reversing Text Script - 28/08/03 01:37 AM

Thank you so much, it works great.
Posted By: pheonix

Re: Reversing Text Script - 28/08/03 01:40 AM

np smile
Posted By: Raccoon

Re: Reversing Text Script - 28/08/03 01:47 AM

Try this thread for a related discussion about "reverse text" some examples if nicer/ faster methods.

It's worth a read if you're interested in learning different scripting styles.

- Raccoon
Posted By: 2big

Re: Reversing Text Script - 28/08/03 01:55 AM

Thanks for the link. I just realized that whenever I reverse the text of someone, it keeps the control codes. How would I incorperate the $strip identifier in there?
Posted By: pheonix

Re: Reversing Text Script - 28/08/03 02:10 AM

if ur using my one:
Code:
alias reverse {  
  var %x,%i = $len($1-)  
  while (%i) {    
    %x = %x $+ $replace($mid($1-,%i,1),$chr(32),_)    
    dec %i  
  } 
  return $strip($replace(%x,_,$chr(32)))
}
Posted By: 2big

Re: Reversing Text Script - 28/08/03 02:46 AM

That still didn't get rid of the numbers that show up with the codes.
Posted By: Raccoon

Re: Reversing Text Script - 28/08/03 02:58 AM

You'll want to $reverse($strip($1-)) instead, so it removes the control codes before reversing them... then it will remove the numbers associated with color codes too.
Posted By: codemastr

Re: Reversing Text Script - 28/08/03 09:03 PM

replacing a space with an _ is a bad idea. What if I want to reverse "this_is_a_test" you've just changed all those _ to spaces giving a result of "tset a si siht" which is incorrect. Instead, you should take advantage of the fact that mIRC does allow you to have a space at the beginning of a variable, just not at the end and therefore you can use:

Code:
alias reverse { 
  var %x,%i = 1 
  while ($mid($1-,%i,1)) {
    %x = $ifmatch $+ %x
    inc %i 
  }  
  return $strip(%x)
}


That is obviously going to be much faster since there are no $replace's involved.
Posted By: rela

Re: Reversing Text Script - 29/08/03 01:35 PM

If you don't replace the space by another character it will leave the space out in the resersed text, I always replace space with $chr(1)
Posted By: Collective

Re: Reversing Text Script - 29/08/03 01:43 PM

His script works without replacing space with anything, although personally I would $strip first..
Posted By: Raccoon

Re: Reversing Text Script - 29/08/03 08:04 PM

Yes, you will $strip first, but the trick behind the space retention is the fact that you're adding to the beginning of the variable.. not the end. (demonstrates for rela)

var %s = $chr(32) $+ %s (works)
var %s = %s $+ $chr(32) (does not)

THAT is the trick behind this method.
Me personally, I prefer binvars.
Posted By: shadowdemon

Re: Reversing Text Script - 30/08/03 12:29 PM

Hi, i read this thread some days ago, and i remember seeing a reverse text script somewhere, been trying for days to remember where, anyways i didnt find the site, but i found the script on one of my CD's, so i must of saved it ages ago.

To the origainal poster, you could always use this code instead, if you havent got anywhere else

Code:
; Reversing words?
; It started when my friend and I decided to talk backward.
; I found it annoying to rephrase my words manually so I wrote this.
; It's not new but I never say it will never work! :)
; Perhaps the way I handle it may not be the best, but oh well, I tried.

; Author: xiao-wen-zi
; Email: smallmoskito@yahoo.com
; Date: 1st January 2002

;
; Usage
;
; /rev &lt;text&gt; returns &lt;echo | say&gt; result
;
; Example
; Input: /rev hi?
; Output: ?ih
;
; $rev(text) returns result
;
;/revd brings up the GUI

alias rev { 

  ;declare variables
  ;%c stores the total number of words found
  var %c $calc($iif($count($$1-,$chr(32)),$ifmatch,0) +1) , %v, %f

  ;words loop - begining from the last word of the sentence to the first
  while ( %c &gt; 0) {
    %f = $gettok($$1-,%c,32) | var %i $len(%f) , %t 

    ;letters loop - begining from the last letter of the word to the first (obviously)
    while (%i) { %t = $+(%t,$right($left(%f,%i),1)) | dec %i }

;adds the reconstructed words to the end of the the rest
    dec %c | %v = %v %t

  }

  ;if is ident., it'll return the result
  if ($isid) { return %v }

  ;if connected to a server it'll say the result
  $iif($server,say,echo) %v
}


;
; Dialog
;

alias revd return $dialog(rev,rev,-1)

dialog rev {
  size -1 -1 200 50
  option dbu
  title "Reverse words?"

  edit "Insert text here",2,5 5 192 12, autohs
  edit "",3,5 20 192 12, read autohs

  button "&amp;Copy reversed words",4,5 36 60 12, default
  button "E&amp;xit",1,166 36 30 12, okay default
}

on *:dialog:rev:*:*: {
  var %e $devent , %n $dname , %d $did
  if (%e == init) { did -fa %n 2 $chr(32) }
  if (%e == edit) &amp;&amp; (%d == 2) { did -o %n 3 1 $rev($did(2)) } 
  if (%e == sclick) &amp;&amp; (%d == 4) { clipboard $did(3) }
}


Checked and tested on mIRC V6.1 (it works)

To Parabrat and/or Hammer or other moderators
I hope you dont mind me pasting the whole code, but i think it was a scriptlet i downlaoded, and just kept on my harddrive and backed up to a cd later

/me gives Parabrat a whole bag of choccy chips cookies or whatever is yer favorite kind wink

ShadowDemon
Posted By: Raccoon

Re: Reversing Text Script - 31/08/03 12:11 PM

I think we've already concluded that there are MUCH faster, cleaner, better methods than the one you just posted. crazy
Posted By: BoredNL

Re: Reversing Text Script - 31/08/03 11:23 PM

although faster, this solution is buggy the way it is.
The text needs to be stripped before being processed, not after, otherwise you'll be left with the color code numbers in the result or loss of text if the color code has numbers behind it.

Here's the fix:
Code:
alias reverse { var %x,%i = 1,%s = $strip($1-)
  while ($mid(%s,%i,1)) { %x = $ifmatch $+ %x |  inc %i }
  return %x }


This script is still not perfect though, as it will shorten multiple spaces to 1 space and all white space before and after the text will be eliminated.
Posted By: shadowdemon

Re: Reversing Text Script - 01/09/03 11:32 PM

yeah i know, it was a few days too late, but i thought you never know, there maybe someone else wanting a reverse text script, who doesnt know where to begin, and this might give them an idea.
© 2022 mIRC Discussion Forums