mIRC Home    About    Download    Register    News    Help

Print Thread
#267335 07/06/20 02:08 PM
Joined: Jul 2006
Posts: 4,145
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
First, something I wasn't necessarily aware, but that probably won't be changed now, using ! to negate a %variable or an identifier inside an if statement works on any token, even on passed parameter:
Code
//alias custi echo -s called custi with $!1- | if (!$false !$false $custi(!$false)) echo -s $v1 -- $v2 | alias custi

Howver, the above will actually fail as a condition, and will trigger the else statement:
Code
 if ($true $true $null) / | else echo -s ??
This looks like a bug to me.


Then, //if (a b) echo -a ?? gives a /if invalid format error, but the format seems valid to me, unsure for how long this has been happening, it should also accept this as valid imo, and sets $v1 to "a b".


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jul 2006
Posts: 4,145
W
Wims Offline OP
Hoopy frood
OP Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Update:

The last case I mentioned in my previous post, the condition has to be 3 tokens, the third token has to return $null while the second token has to return $true or $false.

For example:

Code
//if (a $true %var) echo -ag true $v1 | else echo -ag ok $v1
or
//if (a $($true) $null) echo -ag true $v1 | else echo -ag ok $v1
or 
//if (a $true $+($null)) echo -ag true $v1 | else echo -ag ok $v1
With the exact same rules, if $true or $false is $null instead, mIRC report an empty unknown operator error, maybe having a literal $null as the unknown operator would help.

Also found that mIRC does not choke when the count of '(' and ')' becomes negative, which is really error prone:
Code
//if ) { echo -a ok }
//if (1) && ) { echo -a ok }
Shouldn't that be fixed? I don't see any reason to keep such compatibility.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Dec 2002
Posts: 5,412
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,412
Quote
First, something I wasn't necessarily aware, but that probably won't be changed now, using ! to negate a %variable or an identifier inside an if statement works on any token, even on passed parameter

Indeed, this was added a long time ago.

Quote
Howver, the above will actually fail as a condition, and will trigger the else statement:

That is the intended behaviour. The If statement expects an operator in this context.

Quote
Then, //if (a b) echo -a ?? gives a /if invalid format error,

That is also the intended behaviour. The number of allowed parameters depends on the operator you are using.

The /if statement was implemented very early on in the script parser's implementation. There are no plans to change how it behaves at this point, not least because of the potential this has of breaking backwards compatibility.

Joined: Dec 2002
Posts: 5,412
Hoopy frood
Offline
Hoopy frood
Joined: Dec 2002
Posts: 5,412
Quote
Also found that mIRC does not choke when the count of '(' and ')' becomes negative, which is really error prone:

Thanks, I have added this to my to-do list.

Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
FYI, I encountered something that's related either to this thread or to https://forums.mirc.com/ubbthreads.php/topics/261001/v1-v2-inconsistancy

The $v1 being null relates to the other thread, however it would have been easier to catch if the parenthesis count reaching negative generates an error.

I generally do use parenthesis just because it makes the code easier to read, plus I don't need to remember where they're optional and where they're not. So, I'm more interested in the negative parenthesis count than the other issue. In this example the $v1 is set correctly in the /else condition but is $null in the $true condition

Code
//var %a $rand(0,9) | if $right(%a,1) isin 13579) echo -a $v1 is odd %a | else echo -a $v1 is even %a
//var %a $rand(0,9) | if           %a isin 13579) echo -a $v1 is odd %a | else echo -a $v1 is even %a
//var %a $rand(0,9) | if            3 isin 13579) echo -a $v1 is odd %a | else echo -a $v1 is even %a



Correction: I see now that the $v1 in the $true condition isn't actually $null, it's carried forward from the prior conditional, whether it's a prior if() or while(). Here, when %a is an odd number then $v1 remains as abcd from the prior if()

//var %a $rand(0,9) | if (abcd == defg) noop | if %a isin 13579 echo -a $v1 is odd %a | else echo -a $v1 is even %a


Link Copied to Clipboard