mIRC Homepage
Posted By: Mavric A sophisticated suggestion... - 20/02/04 07:48 PM

I am beginning to learn the techniques of mIRC scripting, but yet at the same time I consider myself a veteran of the C programming language. As I was browsing through the mIRC help file, reading about variables, I found something that could be considered a very good suggestion, and let me tell you smirk

In C, you can modify the alignment of variables within a string by using numbers before the statement, such as:
strlen (buf, "Hello %-14s!");

I think it would be really cool to see alignment variables such as so in mIRC, such as when you do something like this:
alias hello_world {
  var %i = world
  echo -a Hello %-14i !

I understand it would probably be hard to do something like this, but I think it would be a very cool feature, especially with those MTS theme things and custom layouts and so forth.

Any opinions?
Posted By: LocutusofBorg Re: A sophisticated suggestion... - 23/02/04 07:28 AM
You means: you set a variable to a certain value, and then use that variable in another sentence? At least as I understand it, your scriptlet is suppoed to echo Hello world !

This already works in mIRC, in the exact way you pasted it. If you put that code in your remotes and type /hello_world it will echo exactly that....
Posted By: Mavric Re: A sophisticated suggestion... - 23/02/04 08:55 AM

What I meant is not implemented in mIRC in any way right now.

In C, you have string descriptors, which are %s (for strings), %d (for integers), %ld (for long integers), %c (for characters), and %f (for floats).

All of these can be used inside of a string such as so:
char $world[30];
$world = "World!"

sprintf(buf, "Hello %s!", $world);

You can add numbers to these formatting codes to introduce alignment.

So therefor if you did this:
sprintf(buf, "Hello %-15s!", $world);

It would turn out like this:
Hello World          !

This is used to align fixed-length fonts so you can make pretty boxes and stuff.

I think this would be cool to see in mIRC one day.

Only a programmer in C would probably know what I am talking about.

But anyways, good day!
Posted By: DaveC Re: A sophisticated suggestion... - 23/02/04 10:56 AM
you could never implement it like this

echo -a Hello %-14i !

as %-14i is a valid variable name.

create this alias for what you want

alias padder { return $2- $+ $str($chr(32) $+ ,$calc($1 - $len($2-))) $+  }

echo -a Hello $padder(14,%i) !
Posted By: KingTomato Re: A sophisticated suggestion... - 23/02/04 10:24 PM
As dave said, it's not very likely to have such a thing in the mirc language, but you can use such a snipplet to space out values by padding it with other characters. I wrote this snipplet a while go for making columns and tables and such, but can be used for your implimentation.

(To keep the formatting, copy to wordpad first (start>>Run>>"wordpad") then copy from wordpad to mirc)
; -------------------------------------------------------------------------------------------------
; $pad(string, width, align, [pad_chr])
; align is assumed left if unspecified, otherwise use left,right,center
; exaple:
;  /echo -a $pad(Name, 16, center) $pad(Mail, 32, center) $pad(url, 50, center)
;  /echo -a $pad(KingTomato, 16) $pad(kingtomato@kingtomato.com, 32) $pad(www.kingtomato.com, 50)
; you can also use another pad character, other than character 160 (default) by specifying
; it after the alignment. This char can be either the numerical value for the character,
; the character itself, or a string of characters (such as doing [bold][space][bold])
; example:
;  /echo -a $pad(Table Of Contents, 25) Page
;  /echo -a $pad(Introduction, 25, left, .) 1
;  /echo -a $pad(Chapter 1, 25, left, .) 4
;  /echo -a $pad(Chapter 2, 25, left, .) 15
; -------------------------------------------------------------------------------------------------
/pad {
  var %padChr = $iif($4, $iif($4 isnum, $chr($4), $4), $chr(160))
  if ($2 <= $len($1)) return $1
  if ($3 == right) return $+($str(%padChr,$calc($2 - $len($1))), $1)
  else if ($3 == center) {
    var %left = $int($calc(($2 - $len($1)) / 2))
    return $+($str(%padChr,%left), $1, $str(%padChr,$calc(($2 - $len($1)) - %left)))
  return $+($1, $str(%padChr,$calc($2 - $len($1))))
; eof - KingTomato
; -------------------------------------------------------------------------------------------------
Posted By: couresel Re: A sophisticated suggestion... - 24/02/04 12:08 AM
I also have a code which is very similar to this if you'd like to use a 30 line alias laugh

Table Format
© mIRC Discussion Forums