ManualIT Posted September 10, 2022 Share Posted September 10, 2022 I'm trying to create a simple script for getting the hex color value of a position on the screen from a variable given by an input box. The script is not starting because of that error, I don't really understand why it's not working this way, would really appreciate if anyone can explain this to me. #include <MsgBoxConstants.au3> $position = InputBox("", "position:", "", "", 200, 150, @DesktopWidth / 2-125, @DesktopHeight / 2-100, 0) $color = PixelGetColor($position) MsgBox($MB_SYSTEMMODAL,"","Hex Color: " & Hex($color, 6)) Link to comment Share on other sites More sharing options...
Developers Jos Posted September 10, 2022 Developers Share Posted September 10, 2022 2 minutes ago, ManualIT said: I don't really understand why it's not working this way, Did you try opening the helpfile and actually check what the syntax is? 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...
ManualIT Posted September 10, 2022 Author Share Posted September 10, 2022 Not sure what to look for exactly, I know that PixelGetColor should have comma separated value like: PixelGetColor(100, 100) I tried $color = PixelGetColor($position[1],$position[2]) The script starts, but the MsgBox doesn't show Link to comment Share on other sites More sharing options...
Developers Jos Posted September 10, 2022 Developers Share Posted September 10, 2022 So you did read the help page and looked at the example? https://www.autoitscript.com/autoit3/docs/functions/PixelGetColor.htm 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...
ManualIT Posted September 10, 2022 Author Share Posted September 10, 2022 (edited) Yes I did, and the example shows: Local $iColor = PixelGetColor(10, 100) This works fine I know, always used it this way in my scripts. But why in this way it doesn't? $position = "10, 100" Local $iColor = PixelGetColor($position) Edited September 10, 2022 by ManualIT Link to comment Share on other sites More sharing options...
Developers Jos Posted September 10, 2022 Developers Share Posted September 10, 2022 1 hour ago, ManualIT said: But why in this way it doesn't? because PixelGetColor(1,10) is NOT the same as PixelGetColor("1,10"). I would like to refer you to some sort of basic programing course when that's not clear to you yet. 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...
ManualIT Posted September 10, 2022 Author Share Posted September 10, 2022 OK let me just say that I've always thought that whatever value is assigned to a variable that is between quotes, the quotes will be ignored when the variable is called like for example: $sleep = "1000" Sleep($sleep) exit I honestly never knew that I could use Sleep("1000") I always thought it has to be Sleep(1000) without quotes, so using it that way always gave me the idea that quotes will be ignored. And I have always used the Sleep function as the example above in my scripts, so this whole thing got me really confused Link to comment Share on other sites More sharing options...
Solution Musashi Posted September 10, 2022 Solution Share Posted September 10, 2022 (edited) 1 hour ago, ManualIT said: OK let me just say that I've always thought that whatever value is assigned to a variable that is between quotes, the quotes will be ignored when the variable is called (simplified description) AutoIt works internally with the data type Variant. For example, if you pass a string "500" to the Sleep function, AutoIt tries to get the numeric part of it, starting with the first character. Try for demonstration purposes : #include <Timers.au3> Local $hStarttime = _Timer_Init() Sleep("500,2500") ; -> 500 ConsoleWrite("Time elapsed (ms) = " & _Timer_Diff($hStarttime) & @CRLF) $hStarttime = _Timer_Init() Sleep("2500,500") ; -> 2500 ConsoleWrite("Time elapsed (ms) = " & _Timer_Diff($hStarttime) & @CRLF) $hStarttime = _Timer_Init() Sleep("1500A0") ; -> 1500 ConsoleWrite("Time elapsed (ms) = " & _Timer_Diff($hStarttime) & @CRLF) PixelGetColor expects at least 2 parameters (x-coordinate , y-coordinate). If you pass a string like "10, 100", then only the value 10 is evaluated as a parameter. @ManualIT : Additional Info : #include <MsgBoxConstants.au3> Local $sInput = "10, 100" Local $aPosition = StringSplit($sInput, ",", 2) ; 2=$STR_NOCOUNT Local $iColor = PixelGetColor($aPosition[0], $aPosition[1]) MsgBox($MB_SYSTEMMODAL,"","Hex Color: " & Hex($iColor, 6)) However, I would not make this "AutoIt feature" a habit, instead I would pass the data types that the respective function expects . Edited September 10, 2022 by Musashi additional info ManualIT 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
ManualIT Posted September 10, 2022 Author Share Posted September 10, 2022 (edited) Thank you for explaining! From that, now I understand that I have to give 2 different values to PixelGetColor Something like PixelGetColor($value1,$value2) But how can this be done with one input box? Edited September 10, 2022 by ManualIT Link to comment Share on other sites More sharing options...
Musashi Posted September 10, 2022 Share Posted September 10, 2022 4 minutes ago, ManualIT said: But how can this be done with one input box? Check out the small example I added to my post above. You can separate e.g. "10,100" with StringSplit, and then use the two elements of the resulting array. ManualIT 1 "In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move." Link to comment Share on other sites More sharing options...
ManualIT Posted September 10, 2022 Author Share Posted September 10, 2022 Ohhh wow I never knew about StringSplit before 😂 I totally understand now! Man, thank you so much! 👌 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