mIRC Homepage
Posted By: fergie4000 ASCII Alias - 06/02/07 10:02 AM
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.
Posted By: Damsulegna Re: ASCII Alias - 06/02/07 11:11 PM
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
Posted By: Kurdish_Assass1n Re: ASCII Alias - 07/02/07 12:29 AM
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?
Posted By: Riamus2 Re: ASCII Alias - 07/02/07 12:53 AM
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.
Posted By: psycogod Re: ASCII Alias - 07/02/07 01:50 AM
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>,>)
}
Posted By: fergie4000 Re: ASCII Alias - 07/02/07 12:45 PM
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
Posted By: fergie4000 Re: ASCII Alias - 07/02/07 01:12 PM
by the way is there a script like that that can convert hex to text?
and vice versa
Posted By: psycogod Re: ASCII Alias - 09/02/07 12:28 AM
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>,>) }
}
© mIRC Discussion Forums