|
fergie4000
|
fergie4000
|
i have some code to convert text to ascii but it doesn't work whats wrong? /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. /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.
|
|
|
|
Damsulegna
|
Damsulegna
|
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
|
|
|
|
Joined: Apr 2006
Posts: 399
Fjord artisan
|
Fjord artisan
Joined: Apr 2006
Posts: 399 |
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?
|
|
|
|
Joined: Oct 2004
Posts: 8,061
Hoopy frood
|
Hoopy frood
Joined: Oct 2004
Posts: 8,061 |
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.
|
|
|
|
psycogod
|
psycogod
|
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.
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>,>)
}
|
|
|
|
fergie4000
|
fergie4000
|
i'm using it as an alias so /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
|
fergie4000
|
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.
|
|
|
|
psycogod
|
psycogod
|
If you still want here is the modified code, you can use /ascii <text> or /normal <text>. Still works as identifier as well.
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>,>) }
}
|
|
|
|
|