mIRC Home    About    Download    Register    News    Help

Print Thread
#235315 08/12/11 11:31 PM
Joined: Apr 2010
Posts: 966
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 966
If you surround the font-name in quotes, mIRC fails to see it as a fontname that may contain multiple spaces, and reverts to the font set in the options dialog:
Code:
;This returns the width correctly
echo -a Without Quotes: $width(I am testing,Dejavu Sans Mono,50)

;This does not
echo -a With Quotes: $width(I am testing,"Dejavu Sans Mono",50)
Echos the following:
Quote:
Without Quotes: 360
With Quotes: 259



Code to test on your own:
Code:
alias widthtest {
  var %f = $window($active).font
  var %s = $window($active).fontsize 
  echo -a Without quotes(Correct): $width(#,%f,%s)
  echo -a With Quotes(Incorrect): $width(#,$qt(%f),%s)
}

Last edited by FroggieDaFrog; 08/12/11 11:40 PM.

I am SReject
My Stuff
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Generally speaking mIRC doesn't use quotes. Some commands support them when a single parameter may contain spaces, however there's no reason why identifiers must or should support quotes.

Last edited by starbucks_mafia; 09/12/11 01:26 AM.

Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
As stated, you should not be using quotes in identifiers unless otherwise noted in the help file. Quotes are only necessary in commands where mIRC tokenizes $1- by $chr(32) (space)-- in identifiers, $1- is tokenized by $chr(44) (comma), so $2 is already: Dejavu Sans Mono. This is not really a bug. There are instances where mIRC accepts quotes as a convenience, but I don't think mIRC should make a habit of doing that.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Apr 2010
Posts: 966
F
Hoopy frood
OP Offline
Hoopy frood
F
Joined: Apr 2010
Posts: 966
I stumbled upon this, using the following:
Code:
on Me:*:JOIN:#:{ 

  ;I surrounded the window's font in in quotes, so it could be used in a /drawtext event
  var %f = $qt($window(#).font)
  var %s = 50
  var %i = $qt($scriptdirNBGtmp.bmp)
  var %w = $width(#,%f,%s)
  var %h = $height(#,%f,%s)
  var %c = $rgb( [ $regsubex($rgb($color(background)),/(\d+)/g,$abs($calc((255 - \t) /2))) ] )

  window -Bfhp +d @NBGTmp 0 0 %w %h
  drawtext -r @NBGTmp %c %f %s 0 0 #
  drawsave @NBGTmp %i
  background -p # %i
  close -@ @NBGTmp
  .remove %i
}




It seems quite inconsistent that font handling commands such as /font and /drawtext accept quotes (and require them for multi-worded font names), though font handling identifers such as $width()/$height() do not. It's these types of small inconsistencies that make debugging simple scripts like the above more challenging than it should be.

Last edited by FroggieDaFrog; 09/12/11 05:23 AM.

I am SReject
My Stuff
Joined: Oct 2003
Posts: 3,918
A
Hoopy frood
Offline
Hoopy frood
A
Joined: Oct 2003
Posts: 3,918
Again, this is not an inconsistency at all. Quotes are only needed in commands because there is no other way to group arguments tokenized by spaces. In identifiers, arguments are already tokenized by commas, so the quotes are not needed. This is a syntax issue, not a bug in any identifiers. You should not be adding $qt() to your variables, you should be adding them on use. It's easy to rewrite your script using proper syntax:

Code:
var %f = $window(#).font
...
var %w = $width(#,%f,%s)
...
drawtext -r @NBGTmp %c $qt(%f) %s 0 0 #
...


Again, quoting things is only necessary inside of commands, so you should only be adding $qt() in the commands themselves. Taking a step back, it's easy to see why it works the way it does. Ask yourself this: why did you think to add $qt() in the first place? The answer is: because the /window command needed it. $width did not-- so why did you apply the quotes to all commands/identifiers?

The rule is this: quotes are needed in commands, not in identifiers. The quotes are only needed because of the tokenization issues with multiple words and the fact that mIRC tokenizes on spaces. This is not an issue for identifiers, so the need there is moot. Note that this behaviour is consistently applied across mIRC (as noted by your mention that quotes work in your two commands but don't in your two identifiers-- the split here is consistently command vs. identifier). I don't see anything inconsistent/unintended here.


- argv[0] on EFnet #mIRC
- "Life is a pointer to an integer without a cast"
Joined: Dec 2002
Posts: 5,229
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,229
As mentioned in other posts, this is due to commands needing quotes in order to handle words with multiple spaces in them, whereas identifiers already delimit parameters with commas.

Ideally, commands and identifiers would have been designed from the start with support for quotes, unfortunately this was not the case and adding support for them now is tricky.

Previously, I have made identifiers handle quotes for parameters on a case-by-case basis, eg. for identifiers that use filenames, when scripters point them out. I will update $width/$height to handle quotes for the font name for the next version.


Link Copied to Clipboard