Jump to content

Recommended Posts

  • Moderators
Posted (edited)

I have been porting some scripts from 3.3.10.2 to 3.3.12.0 (SciTE 14.06.03.20), and noticed odd behavior with a ternary call. I am looking back through the changelog, but don't see anything regarding a change between the two versions. Can someone confirm I am not being thick?

Reproducer:

;I work in 3.3.10.2 but fail beginning in 3.3.11.6 Beta
;The error in 3.3.11.6 is "Statement cannot be just an expression"

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
$mode = 2

($mode = 1) ? (GUICreate("Test Mode 1", 300, 300)) : (GUICreate("Test Mode 2", 300, 300))
GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd

GUIDelete()

I did do some backwards testing down to 3.3.11.0, and found the problem has existed since 3.3.11.6.

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

  • Moderators
Posted

I'm not sure if I understand your question; it is not really a matter of whether there is a workaroud if that is what you are asking, I can always go with an if-else statement. I am merely curious as to what caused the change in behavior.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

  • Moderators
Posted

JLogan3o13,

It is an Au3Check "error" - if you add #AutoIt3Wrapper_Run_AU3Check=n then the code runs without problem. I imagine it was a change made when Au3Check was updated to cope with the ternary operator - you need to add some form of assignment. Doing this:

$hGUI = ( ($mode = 1) ? (GUICreate("Test Mode 1", 300, 300)) : (GUICreate("Test Mode 2", 300, 300)) )
works fine. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

In C# the code in post #1 is invalid as ternary is to be used as a conditional assignment, which I guess is the case with most languages.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

  On 6/23/2014 at 4:14 PM, Melba23 said:

JLogan3o13,

It is an Au3Check "error" - if you add #AutoIt3Wrapper_Run_AU3Check=n then the code runs without problem. I imagine it was a change made when Au3Check was updated to cope with the ternary operator - you need to add some form of assignment. Doing this:

$hGUI = ( ($mode = 1) ? (GUICreate("Test Mode 1", 300, 300)) : (GUICreate("Test Mode 2", 300, 300)) )
works fine. :)

M23

 

for me it is an AutoIt error as expression without affectation is not a valid construction

a statement as 1+1 is not legal either for me

  • Moderators
Posted

jpm,

If you code the line correctly - as trancexx has kindly (and not for the first time) indicated - the problem is completely banished. I intentionally put quotes around

  Quote

Au3Check "error"

as I did not see it as a real problem and I was most definitely not expecting you to amend Au3Check - I have the greatest aversion to asking anyone to enter that particular circle of hell! :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted
  On 6/23/2014 at 4:54 PM, jpm said:

for me it is an AutoIt error as expression without affectation is not a valid construction

a statement as 1+1 is not legal either for me

Meh, you don't even know the rules of the language you are developer of. That's terrible jpm.

♡♡♡

.

eMyvnE

  • Moderators
Posted

  On 6/23/2014 at 4:50 PM, trancexx said:

Just a small remark if I may. More correct usage of the operator would be:

 

Thanks for this.

 

  Quote

Purpose of ternary operator is not to replace If...Then. 

 

If this was for me, I agree. I was simply responding to what I perceived to be JScript's question by stating there is another way to get the same effect.

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted
  On 6/23/2014 at 5:03 PM, trancexx said:

Meh, you don't even know the rules of the language you are developer of. That's terrible jpm.

many thanks for your sarcasm

I still think expression which differ from a simple call should be an error

Posted

Me too.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

For now Au3Check should be rectified to honour that code. I personally treat ternary usage as I would in C#.

 

Func Adlib($vFunc, $bDereg = False)
    Local $hAdLib = ($bDereg ? AdlibUnRegister : AdlibRegister)
    $hAdLib($vFunc)
EndFunc

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

  On 6/25/2014 at 1:14 PM, guinness said:

For now Au3Check should be rectified to honour that code. I personally treat ternary usage as I would in C#.

 

Func Adlib($vFunc, $bDereg = False)
    Local $hAdLib = ($bDereg ? AdlibUnRegister : AdlibRegister)
    $hAdLib($vFunc)
EndFunc

I don't get any au3check error on this code

The one from trancexx does not fir fromp the fact that it is an expression not just a function call

Posted

No, that code is fine. I was just demonstrating how I personally use ternary. trancexx's code is the one which shouldn't display an Au3Check because AutoIt quite happily parses it.

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...