while()

Alhifar

Member
Shouldn't while evaluate its conditions in order? e.g.
Code:
 while( ( offers = visit_url( "makeoffer.php" ) ) && contains_text( offers , "Pending Trade Offers (Incoming)" ) )

Should do what is in the loop as long as you have pending incoming trades, shouldn't it?

If not, can someone smarter than me explain why it isn't like that?
 

jasonharper

Developer
The operand of while is evaluated as an expression, but assignment in ASH is ALWAYS a statement, not an expression. The first part of your condition is being interpreted as a comparison with the existing value of 'offers', not an assignment to it.
 

Bale

Minion
... I'm not sure I understand that answer ...

First it considers offers as a boolean and then it assigns it as visit_url( "makeoffer.php" )?
 

jasonharper

Developer
There is no assignment being done here. That code would perform assignment if it was a statement, but as an expression, it's comparing the existing value of 'offers' to the result of the visit_url() (exactly as if that = was a ==).
 

Veracity

Developer
Staff member
Used to be, if you used a single = in a conditional, KoLmafia gave you an error message. holatuwol changed it so that = would be the synonym of ==, in that context. He thought it would less confusing for scripters. I thought it would be MORE confusing for scripters.

Looks like I was correct - in this case, at least.

I see three possibilities:

1) Allow assignments to be part of expressions (Boo, hiss, too much work)
2) Make a single "=" in an expression give an error, since it's not REALLY an operator
3) Pretend that a single "=" is the same as double "==" in expressions.

We currently have 3.
I'm willing to put it back to 2 - and maybe, eventually, no promises or schedules, 1.

Any thoughts from other scripters?
 

Bale

Minion
I agree with you about = not being equivalent to == simply because it is allowed in other languages. If mafia doesn't throw an error, then we naturally expect it to work as an assignment. Only an inexperienced programmer would be helped by that.
 

Alhifar

Member
I second the agreement from Bale. It would be more helpful to me to error out because of it being invalid than me thinking it is doing something it isn't. It shouldn't be too hard for anyone happening to take advantage of that feature to change their script to use "==" instead of "=", in my humble opinion.
 

Bale

Minion
It's nice that #2 was implemented, but embarrassing how virtually every script was broken by it. :p We're all such sloppy programmers.
 

zarqon

Well-known member
I must note as a matter of pride that I did not write any of the code that needed fixing due to this fix.

I must then note as a matter of humility that I shamelessly borrowed code from other scripters. :)
 
Top