mIRC Homepage
Posted By: sparta $calc - $len problem - 06/10/11 09:55 AM
I using this code to show away users in a channel:
Code:
alias awayscan {
 set %awscan .
 set %chan $1
  if ($window(@aws)) { window -c @aws }
  window -lCk0 @aws 50 50 700 376 Verdana 11
  aline @aws Scanning for away users in %chan
  aline @aws Away $+ $str($chr(160),2) $+ Address $+ $str($chr(160),33) $+ Nicks
  if ($hget(awayscan)) { hfree awayscan }
  hmake awayscan $nick(%chan,0)
  .who %chan
}


raw 352:*: {
  if (%awscan) {
    haltdef
    if (G isin $7) {
      hadd awayscan  $+($3,@,$4)
    }
  }
}
raw 315:*: {
  haltdef
  var %as = $hget(awayscan,0).item
  while (%as) {
    var %ad = $hget(awayscan,%as).item
    aline @aws %as $str($chr(160),8) $+ $hget(awayscan,%as).item $+ $str($chr(160),$calc(32 - $len(%ad))) $+ $nick(%chan,%as)
    dec %as
  }
}

The line:
aline @aws Away $+ $str($chr(160),2) $+ Address $+ $str($chr(160),33) $+ Nicks

will ad like a menu in bold, and now i want to put the amount of away users below Away, hosts below hosts, and nick below nicks . The problem i have is that i cant get the nick part to line up as it should. any bether way to do this then to use $calc ?

Using the var %awscan as a way to halt the code, using raw 352 to more scripts then this one. And need to recive data in different ways depending on script.
Posted By: Riamus2 Re: $calc - $len problem - 06/10/11 10:19 AM
I'd use $width instead of $len to calculate where to put the text. It will be more accurate for variable width fonts. Beyond that, there isn't a great way to handle aligning text in columns unless you want to use a picture window.

* Note that you'll also need to know the $width of your space to know how many you'll need.
Posted By: Wims Re: $calc - $len problem - 06/10/11 02:32 PM
It might be possible to do something with $width but actually, there is a better and easier way to handle this:
Code:
alias awayscan {
  set %awayscan #$1
  if (!$window(@aws)) window -lCkM -t50,50 @aws 50 50 700 376 Verdana 11
  aline @aws Scanning for away users in #$1
  aline @aws Nick $chr(9) Address
  who #$1
}

raw 352:*: {
  if (%awayscan == $2) {
    haltdef
    if (G isin $7) aline @aws $6 $chr(9) $+($3,@,$4)
  }
}

raw 315:*: {
  if (%awayscan == $2) { 
    haltdef
    unset %awayscan
  }
}
Posted By: Riamus2 Re: $calc - $len problem - 06/10/11 03:14 PM
Good point. I didn't realize tabs worked in custom windows. Just make sure the text isn't too long, or at least make sure to use enough $chr(9)'s to make sure there is space between the columns. Unlike what someone may expect, a $chr(9) won't tab over to the next tab stop after the current location unless you're before the first tab stop. To get to the second tab stop, you always need two $chr(9)'s regardless of whether your text already takes you beyond the first tab stop.
Posted By: Wims Re: $calc - $len problem - 06/10/11 03:33 PM
-M in /window handles a too long text for you but
Quote:
or at least make sure to use enough $chr(9)'s to make sure there is space between the columns. Unlike what someone may expect, a $chr(9) won't tab over to the next tab stop after the current location unless you're before the first tab stop. To get to the second tab stop, you always need two $chr(9)'s regardless of whether your text already takes you beyond the first tab stop.
What? $chr(9) seperates columns, you need only one to get to the second column
Posted By: Riamus2 Re: $calc - $len problem - 06/10/11 04:58 PM
Yes, -M will handle chopping text at tab stops, but isn't necessarily what you want unless you don't care about seeing all of your text. I think it's better to use enough tabs to guarantee the text is aligned properly without truncating text, which is what I mentioned. Now, depending on the network, the max nick length may be low enough to not be a problem. But on other networks, one tab may not work.

Below is an explanation of what I was talking about regarding use of multiple tabs.

//aline @test 1234 $chr(9) $chr(9) $+ 1234

See where the second set of numbers are. Now, use a number that is too long in the beginning...

//aline @test 12345678901234567890 $chr(9) $+ 1234

Notice that it does not tab to the next tab stop, but instead just adds a couple spaces. It will not align that way.

Now, try it with two $chr(9)'s...

//aline @test 12345678901234567890 $chr(9) $chr(9) $+ 1234

It now aligns properly.


Notes:
* The $+ is just to remove the space following the tab so the number appears at the tab stop instead of one space later.

* I'm testing this on 6.35 as I don't have 7.19 installed at work. It is possible that it may have been changed since then.
Posted By: sparta Re: $calc - $len problem - 07/10/11 08:05 AM
Thank you, i try using your code so maybe i get it the way i want it. smile
Posted By: Wims Re: $calc - $len problem - 07/10/11 05:36 PM
Well, not really. This is only because there's two tab position, add one more and you'll see it doesn't add a couple spaces, but correctly use the third tabstop.
Posted By: Riamus2 Re: $calc - $len problem - 08/10/11 01:15 AM
If you read what I said, that's the point I was making. You have to add the right number of tabs or it will not align. It's not like a text editor or word processor, where if you're past the first tab stop and press Tab, then it goes to the next tab stop. Instead, it adds a space and that's all. If you "hit Tab" again, then it will go to the next tab stop. The point of what I said right at the start is that you need to be aware of the difference between this behavior and what most people are used to.

In case you're still not seeing it...

Word Processor:
Let's say tabs are every 1/2". If I type enough to be 3/4", hitting Tab afterwards will move me to the next tab stop (at 1").

mIRC/$chr(9):
Again, let's say tabs are every 1/2" and I type enough to be at 3/4". I then "hit Tab" by using $chr(9) and instead of going to 1", it adds a space or two because it still wants to go to the first tab instead of the next tab. If I "hit Tab" again, only then will it go to 1". This is different from how tabs work in basically any other software, which is why I commented on it.

And, btw... my previous example aligns fine with 2 tabs. 3 isn't necessary.
© mIRC Discussion Forums