Jump to content

Schrödinger's variable


Recommended Posts

I am fairly new to the scripting world, but I've run into an issue that I cannot understand. I have a script in which I initialize a variable as 0 so that it can be checked later for any change. Initially the value changed to another Int, so there was never an issue, but later I modified the script to change the data to a text string but left the initialized variable as 0 instead of "" simply because it's just a simple quick 'n' dirty script that will be discarded soon.

Later in the script I have an If...Then statement that checks if the variable is still 0, and if it is will end the script with an error. The issue is that the If statement somehow still triggers even if the variable changes, but the variable will simultaneously read correctly as whatever it was changed to. An example to illustrate what I mean:

Local $var = 0
$var = "Test"

If $var = 0 Then MsgBox(4096, "", "The variable is: " & $var)

This only appears to happen when the initial value is set to 0 and is then changed to a text string. If it is any other int or text string or if the value changes to another integer, everything works as I would expect. Is this intended behavior? Am I missing something?

I tried searching around was unable to find anything, so here I am.

Link to comment
Share on other sites

Hi,

AutoIt interperts the variables differently from other languages, you are comparing a string to an integer, the string is converted to an integer and since it's not an interpretable number it's converted to 0.

Br, FireFox.

Link to comment
Share on other sites

Thanks all for the information. Especially the bit about the double equal. Totally slipped my mind.

To check my understanding of the answer from FireFox; this occurs because the variable is initially interpreted as an integer but since it later changes to a string, that string gets converted to an integer; which evidently is always zero since its not a valid integer; thus causing any conditional checking whether it is zero to trigger while simultaneously evaluating the variable correctly when called? This would explain why any int other than zero seems to work just fine.

Edited by Synitare
Link to comment
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
 Share

  • Recently Browsing   0 members

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