mIRC Home    About    Download    Register    News    Help

Print Thread
#170272 06/02/07 10:02 AM
Joined: Feb 2007
Posts: 3
F
Self-satisified door
OP Offline
Self-satisified door
F
Joined: Feb 2007
Posts: 3
i have some code to convert text to ascii but it doesn't work whats wrong?
Code:
/ascii { var %x 0 | var %y $len($1-) | var %t $null | :under | inc %x | if ( %x > %y ) { msg $chan %t | halt } | %t = %t $asc($mid($1-,%x,1)) | goto under }

i also have the code to change it back but that doesn't work either.
Code:
/normal { var %x 0 | var %y $numtok($1-,32) | var %t $null | :over | inc %x | if ( %x > %y ) { msg $chan %t | halt } | if ( $gettok($1-,%x,32) == 32 ) { inc %x | %t = %t $chr($gettok($1-,%x,32)) | goto over } | %t = %t $+ $chr($gettok($1-,%x,32)) | goto over }

problems with both it crashes my mirc.
ps thanks to kando for the help already.

fergie4000 #170306 06/02/07 11:11 PM
Joined: May 2003
Posts: 41
D
Ameglian cow
Offline
Ameglian cow
D
Joined: May 2003
Posts: 41
use an = sign on VARs


var %x = 0 | var %y = $len($1-) | var %t = $null


same with the others
var %x = 0 | var %y = $numtok($1-,32) | var %t = $null


If At First You Don't Succeed, Ask Someone For Help......
Damsulegna #170310 07/02/07 12:29 AM
Joined: Apr 2006
Posts: 400
K
Fjord artisan
Offline
Fjord artisan
K
Joined: Apr 2006
Posts: 400
to be honest, I hardly use ='s for var, and it works just as good, at least for me it does, I tested your script and it worked fine, can you show what you are typing?


-Kurdish_Assass1n
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Originally Posted By: Kurdish_Assass1n
to be honest, I hardly use ='s for var, and it works just as good, at least for me it does, I tested your script and it worked fine, can you show what you are typing?


In most cases, you can get away with not using = in a /var, but there are specific cases that will not work if you don't include the = sign. It is *always* a good idea to follow correct syntax rather than using shortcuts, or you end up running into unexpected problems that are hard to track down.

Of course, considering all of that is on a single line rather than *nicely* spaced out over multiple lines, it will already be harder to track down problems than it would otherwise.


Invision Support
#Invision on irc.irchighway.net
fergie4000 #170315 07/02/07 01:50 AM
Joined: Dec 2002
Posts: 43
P
Ameglian cow
Offline
Ameglian cow
P
Joined: Dec 2002
Posts: 43
This solution may not be perfect, hope it works for you though. I assume you are using mIRC 6.21, since you did not say. If you want to use this to say something in the channel use /msg $chan $ascii(text) or /msg $chan $normal(text). You could use $isid to see if it is an identifier or command, and message the channel if its a command.

Code:
ascii {
  var %c = 1
  var %ret
  while (%c <= $len($1)) {
    /* use $mid($1,%c,1) gets char from position stored in %c
    *  use $asc() to convert character to ascii
    *  use $base to convert to base 16, and 0 pad line
    *    this allows spaces to be removed
    */
    var %ret = %ret $+ $base($asc($mid($1,%c,1)),10,16,2)
    inc %c
  }
  return %ret
}

normal {
  var %c = 1
  var %ret
  while (%c <= $len($1)) {
    var %chr = $mid($1,%c,2)
    /* to handle spaces correctly, convert them to a unique sequence <space>
    *  change < to <lt> and > to <gt>, just in case "<space>" is in the text
    */
    if (%chr == 20) {
      var %ret = %ret $+ <space>
    }
    elseif (%chr == 3C) {
      var %ret = %ret $+ <lt>
    }
    elseif (%chr == 3e) {
      var %ret = %ret $+ <gt>
    }
    else {
      var %ret = %ret $+ $chr($base(%chr,16,10))
    }
    inc %c 2
  }
  ;use $replace to get $chr(32), $chr(60), and, $chr(62) back
  return $replace(%ret,<space>,$chr(32),<lt>,<,<gt>,>)
}

psycogod #170332 07/02/07 12:45 PM
Joined: Feb 2007
Posts: 3
F
Self-satisified door
OP Offline
Self-satisified door
F
Joined: Feb 2007
Posts: 3
i'm using it as an alias so
Code:
/ascii this is an example

and by the way i'm on 6.17 at the moment

*edit*
fixed it i remove the | and added line breaks.
thanks everybody
especially kando cos its his script :P

Last edited by fergie4000; 07/02/07 01:07 PM.
fergie4000 #170334 07/02/07 01:12 PM
Joined: Feb 2007
Posts: 3
F
Self-satisified door
OP Offline
Self-satisified door
F
Joined: Feb 2007
Posts: 3
by the way is there a script like that that can convert hex to text?
and vice versa

Last edited by fergie4000; 07/02/07 01:13 PM.
fergie4000 #170449 09/02/07 12:28 AM
Joined: Dec 2002
Posts: 43
P
Ameglian cow
Offline
Ameglian cow
P
Joined: Dec 2002
Posts: 43
If you still want here is the modified code, you can use /ascii <text> or /normal <text>. Still works as identifier as well.

Code:
ascii {
  var %c = 1
  var %ret
  while (%c <= $len($1-)) {
    /* use $mid($1-,%c,1) gets char from position stored in %c
    *  use $asc() to convert character to ascii
    *  use $base to convert to base 16, and 0 pad line
    *    this allows spaces to be removed
    */
    var %ret = %ret $+ $base($asc($mid($1-,%c,1)),10,16,2)
    inc %c
  }
  if ($isid) { return %ret }
  elseif ($chan) { msg $chan %ret }
}

normal {
  var %c = 1
  var %ret
  while (%c <= $len($1-)) {
    var %chr = $mid($1-,%c,2)
    /* to handle spaces correctly, convert them to a unique sequence <space>
    *  change < to <lt> and > to <gt>, just in case "<space>" is in the text
    */
    if (%chr == 20) {
      var %ret = %ret $+ <space>
    }
    elseif (%chr == 3C) {
      var %ret = %ret $+ <lt>
    }
    elseif (%chr == 3e) {
      var %ret = %ret $+ <gt>
    }
    else {
      var %ret = %ret $+ $chr($base(%chr,16,10))
    }
    inc %c 2
  }
  ;use $replace to get $chr(32), $chr(60), and, $chr(62) back

  if ($isid) { return $replace(%ret,<space>,$chr(32),<lt>,<,<gt>,>) }
  elseif ($chan) { msg $chan $replace(%ret,<space>,$chr(32),<lt>,<,<gt>,>) }
}


Link Copied to Clipboard