Synitare Posted October 2, 2013 Share Posted October 2, 2013 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 More sharing options...
FireFox Posted October 2, 2013 Share Posted October 2, 2013 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 More sharing options...
Developers Jos Posted October 2, 2013 Developers Share Posted October 2, 2013 ... and you need to use a double equal sign to compare AlphaNumerical. SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
AndyG Posted October 2, 2013 Share Posted October 2, 2013 ....and you should use someting like IsString($var) to be sure that $var is a string Link to comment Share on other sites More sharing options...
Synitare Posted October 2, 2013 Author Share Posted October 2, 2013 (edited) 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 October 2, 2013 by Synitare Link to comment Share on other sites More sharing options...
Xandy Posted October 2, 2013 Share Posted October 2, 2013 (edited) Mathematically "Test"= 0 Once you reassign $var to "Test" the past value of 0 is lost! Edited October 2, 2013 by Xandy Human Male Programmer (-_-) Xandy About (^o^) Discord - Xandy Programmer MapIt (Tile world editor, Image Tile Extractor, and Game Maker) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now