mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2003
Posts: 11
K
killer Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: Jan 2003
Posts: 11
Would it be possible to add this feature?

i.e.

if ((%variable = unknown_value) == test_value) { commands involving %variable }

Yes, there are other methods of acheiving similar end results, such as: defining the variable prior to the if-statement, using $ifmatch instead (which will not work outside the original if-statement once any other if-statement has been processed), creating an alias, etc. I am not interested in these.

I feel it would be more efficient and concise if I simply did the comparrison and the variable declaration in at one time. I've done this in C before and it made the code, in my opinion, much more simple.

After thought: Wow, I wonder how often syntax is suggested?

Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
correct me if im wrong but.

if ((%variable = unknown_value) == test_value) { commands involving %variable }

is not gonna be any better than
%variable = unknown_value
if (%variable == test_value) { commands involving %variable }

you must be setting it then testing it, then perhaps using it

I saw you said you have done this in C, I would feel sure, that if you actually back enginered the code created from your example (in C) you would find its simply , sets the variable , tests the vaiable then performs what ever based on that, in fact i know it would have to.

Of course on the other hand being able to do what you say in something like this...
if ((%condition == $true) && ((%variable = unknown_value) == test_value)) { commands involving %variable }

well that would be nice, i guess, as only if %condition was true would the %variable ever be created, then again u could just create it after testing if unknown_value == test_value, that of course would need $ifmatch or a refetching of unknown_value, and im assuming your talking about some unknown_value that maybe time or resource consuming to get.
I can see the problem using $ifmatch if the IF condition was more complex, like there was more than one unknown_value being checked against its test_value, So well damn it, by the time i finished writting YES i think this would be a good idea.

Joined: Dec 2002
Posts: 2,809
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Dec 2002
Posts: 2,809
Well it is very useful in C/C++. One common use is something like:

if (!(%var = $somefunc()))

Yes you're right,
%var = $somefunc()
if (!%var)

is equivilent, but the other is shorter (and in an interpretted language that means faster), and cleaner.

The problem? Although I think this is a great idea, I don't think it should be added. Unfortunately, mIRC treats = just like ==. So if someone has:
if (%var = 1)
in mIRC, that is equivilent to:
if (%var == 1)

while it is bad style to use the = instead of ==, a lot of scripts do it, and changing the way = works would break those scripts. The only way I can see this being added is if the suggestion (I forget who suggested it) about pragmas are added:
pragma equal-is-assignment on

That would make it so that = is treated as the assignment operator rather than the relational equality operator. If that pragma were not specified, then it would just function like it currently does.

Joined: Jan 2003
Posts: 11
K
killer Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: Jan 2003
Posts: 11
Wow, I didn't know that = works as ==. I guess that sort of shoots my idea down the drain, then. I wish that could be changed. I don't think it does anyone any good to have it that way, it only promotes poor programming skills and a Verizon FreeUP^^-esque scripting language.

Joined: Feb 2003
Posts: 810
C
Hoopy frood
Offline
Hoopy frood
C
Joined: Feb 2003
Posts: 810
Well maybe there could exist another format for that instead of just enclosing the declaration into parenthesis. I also think it could be used everywhere, not only /if statements.

I don't know how could it be, just an (ugly?) example:
if (%x) && ($blah(%y) > { var %z = %x + %y }) { bleh %z }

Anyway, not really related to this, I'd like to have an identifier like $ifmatch, but returning the 2nd parameter of an if-then-else comparison.


* cold edits his posts 24/7

Link Copied to Clipboard