Sign in to follow this  
Followers 0
FinalVersion

C Style If

9 posts in this topic




Why can't you have this sort of If statement? Or am I just coding it wrong?

If ($Var = Function(..., ...)) == 0 Then

I could say not correct.

If $Var == Function(..., ...) Then

or

If NOT $Var == Function(..., ...) Then

There is no need for the additional level of comparison. I am assuming you are not doing assignment in your example, this Function returns 5 so $var = 5 then doing if 5 equals 0.

I have never done this in C so I can't say if it works but would be hit over the head for trying it.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

$var = Function(..., ...)
If ($var == "something_the_function_returned") Then ; == means case-sense
EndIf

You mean like this?


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

If (Add(5, 5) = 10) Then
    MsgBox(0, "", "Succes!")
EndIf

If (Paste("Hello", "World") == "HelloWorld") Then
    MsgBox(0, "", "Succes!")
EndIf

Func Add($Param1, $Param2)
    Return $Param1 + $Param2
EndFunc

Func Paste($Param1, $Param2)
    Return $Param1 & $Param2
EndFunc

As far as I know, you can't declare a variable inside an If statement. Im coding C# and know what you mean.

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I know, refresh the page and read my previous post again. :mellow:

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

regardless of the fact that '==' is a string comparison....

2 cases are possible in if/then:

if TRUE then

if FALSE then  ;or  if 0 then ...   everything other than 0 is TRUE
 

so you have to distinguish if the expression (($Var = Function(..., ...)) = 0) is true or not

($Var = Function(..., ...)) could be TRUE or FALSE, nothing else!

so the expression TRUE=0 has the result FALSE

and FALSE=0 has the result TRUE

Example:

For $var = 1 To 3
    For $para = 1 To 2

        If ($var = _Function($para)) = 0 Then ;is it true or false?
            MsgBox(0,"$var="&$var&"  $para="&$para&"  -->  "& (($var = _Function($para)) = 0), "(" & $var & " = _Function(" & $para & "))  is " & ($var = _Function($para)) & @CRLF & "so " & ($var = _Function($para)) & " = 0   is " & (($var = _Function($para)) = 0))
        Else
            MsgBox(0,"$var="&$var&"  $para="&$para&"  -->  "& (($var = _Function($para)) = 0), "(" & $var & " = _Function(" & $para & "))  is " & ($var = _Function($para)) & @CRLF & "so " & ($var = _Function($para)) & " = 0   is " & (($var = _Function($para)) = 0))
        EndIf

    Next
Next


Func _function($a)
    Return $a
EndFunc   ;==>_function

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0