JustCallMeAlec Posted July 29, 2023 Share Posted July 29, 2023 (edited) Hello, so I'm writing this script that is taking the user's input and I'm trying to add the number that's put in to define what variable to use. So for example let's say I have 3 Variables: Quad1X1, Quad2X1, and Quad3X1, and I want to use a Input box to put a number in to decide which Quad I use. (So if 1 is put in the InputBox, I want the variable that's used to be Quad1X1, if I put 2 in it, then Quad2X1, etc.) Currently where I sit is the number I put in the box gets converted to what variable I want, but the problem being it's seen as text, not an actual variable. So if I put in 1, then I end up with "$Quad1X1", not the value of Quad1X1. The end result I'm looking for is making the variable "$QuadC1X1" equal 223 (If I put in a 1 in the Input Box as defined at the top via the variable "$Quad1X1") Where am I going wrong here? Also sorry for the debug text, I've been throwing things at a wall for five hours Edit: Just realized I didn't have a Comma in my ToolTip, but it's not what's causing the frustration I don't think. expandcollapse popup#include <array.au3> #include <MsgBoxConstants.au3> Global $iLoop = True Global $Quad1X1 = 223 ; Top Left Global $Quad1Y1 = 224 ; Top Left Global $Quad1X2 = 324 ; Top Right Global $Quad1Y2 = 224 ; Top Right Global $Quad1X3 = 224 ; Bottom Left Global $Quad1Y3 = 325 ; Bottom Left Global $Quad1X4 = 324 ; Bottom Right Global $Quad1Y4 = 325 ; Bottom Right HotKeySet("{PGDN}", "GetOutaHere") HotKeySet("{PGUP}", "Begin") HotKeySet("{INS}{DEL}", "Kill") HotKeySet("{HOME}", "InputVariable") $QuadShowVariable = InputBox("Input Box", "Which quadrant to show? Number only.") $QuadC1X1 = "Quad" & $QuadShowVariable & "X1" $QuadC1X1 = "$Quad" & $QuadShowVariable & "X1" $QuadC1X2 = "Quad" & $QuadShowVariable & "X2" $QuadC1Y1 = "Quad" & $QuadShowVariable & "Y1" $QuadC1Y2 = "Quad" & $QuadShowVariable & "Y2" ;Assign("" ;Local $QuadC1X1[3] ;Assign("QuadC1X" ;$QuadTestVariable = $"Quad" & $QuadShowVariable & "X1" ;$Quad1X1 = While 1 ToolTip("Ready" & @CRLF & "PGUP - Begin" & @CRLF & "PGDN - Pause" & @CRLF & "INS + DEL - Close" & @CRLF & "HOME - Change quadrants" & @CRLF & "QuadC1X1 = " & $QuadC1X1 & @CRLF & "$Quad1X1 = " & $Quad1X1 400, 10) Sleep(250) WEnd Func Begin() $iLoop = True While $iLoop = True TheLoop1() If $iLoop = False Then ExitLoop TheLoop2() If $iLoop = False Then ExitLoop TheLoop3() If $iLoop = False Then ExitLoop TheLoop4() If $iLoop = False Then ExitLoop WEnd $iLoop = False EndFunc ;First Func TheLoop1() ToolTip("X1/Y1 of quadrant " & $QuadC1X1 & " " & $QuadC1Y1, 900, 10) MouseMove($QuadC1X1, $QuadC1Y1, 0) Sleep(1) EndFunc Func TheLoop2() ToolTip("X2/Y2 of quadrant " & $QuadShowVariable, 900, 10) MouseMove($Quad1X2, $Quad1Y2, 0) Sleep(1) EndFunc Func TheLoop3() ToolTip("X3/Y3 of quadrant " & $QuadShowVariable, 900, 10) MouseMove($Quad1X3, $Quad1Y3, 0) Sleep(1) EndFunc Func TheLoop4() ToolTip("X4/Y4 of quadrant " & $QuadShowVariable, 900, 10) MouseMove($Quad1X4, $Quad1Y4, 0) Sleep(1) EndFunc Func GetOutaHere() $iLoop = False EndFunc Func Kill() Exit 0 EndFunc Edited July 29, 2023 by JustCallMeAlec Just realized I didn't have a comma in my ToolTip, but that wasn't the issue. Link to comment Share on other sites More sharing options...
Andreik Posted July 29, 2023 Share Posted July 29, 2023 Check in help file Eval() function. Musashi 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
JustCallMeAlec Posted July 29, 2023 Author Share Posted July 29, 2023 35 minutes ago, Andreik said: Check in help file Eval() function. Didn't help. Appreciate the suggestion. Link to comment Share on other sites More sharing options...
Andreik Posted July 29, 2023 Share Posted July 29, 2023 At least you tried? $Quad1X1 = 1 $Quad2X1 = 2 $QuadShowVariable = InputBox("Input Box", "Which quadrant to show? Number only (1-2).") $QuadC1X1 = Eval("Quad" & $QuadShowVariable & "X1") MsgBox(0,'', $QuadC1X1) When the words fail... music speaks. Link to comment Share on other sites More sharing options...
junkew Posted July 29, 2023 Share Posted July 29, 2023 Please check out multi dimensionale arrays https://www.autoitscript.com/wiki/Arrays FAQ 31 How to click some elements, FAQ 40 Test automation with AutoIt, Multithreading CLR .NET Powershell CMDLets Link to comment Share on other sites More sharing options...
Solution ioa747 Posted July 29, 2023 Solution Share Posted July 29, 2023 I agree with the array approach example: expandcollapse popup; https://www.autoitscript.com/forum/topic/210615-converting-string-into-a-variable-name/?do=findComment&comment=1521771 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <array.au3> Global $id = 0 ; active selection Global $aQuad[][] = [ _ ["X", "Y", "W", "H"], _ [100, 100, 200, 200], _ [200, 100, 300, 300], _ [500, 200, 800, 600], _ [300, 300, 1000, 700]] ;~ _ArrayDisplay($aQuad) While 1 Global $sInputBoxAnswer = InputBox("Which quadrant to show?", @CRLF & "Number only", $id + 1) Select Case @error = 0 ;OK - The string returned is valid ConsoleWrite("$sInputBoxAnswer=" & $sInputBoxAnswer & @CRLF) $id = Int($sInputBoxAnswer) If $id > 0 And $id <= UBound($aQuad) - 1 Then ConsoleWrite("X=" & $aQuad[$id][0] & ", ") ConsoleWrite("Y=" & $aQuad[$id][1] & ", ") ConsoleWrite("W=" & $aQuad[$id][2] & ", ") ConsoleWrite("H=" & $aQuad[$id][3] & @CRLF) MouseMove($aQuad[$id][0], $aQuad[$id][1]) ToolTip($aQuad[$id][0] & ", " & $aQuad[$id][1], $aQuad[$id][0], $aQuad[$id][1], "MouseMove XY") Sleep(500) MouseMove($aQuad[$id][2], $aQuad[$id][3]) ToolTip($aQuad[$id][2] & ", " & $aQuad[$id][3], $aQuad[$id][2], $aQuad[$id][3], "MouseMoveWH") EndIf Case @error = 1 ;The Cancel button was pushed Exit EndSelect Sleep(3000) ConsoleWrite("" & @CRLF) ToolTip("") WEnd Musashi and JustCallMeAlec 1 1 I know that I know nothing Link to comment Share on other sites More sharing options...
JustCallMeAlec Posted July 30, 2023 Author Share Posted July 30, 2023 14 hours ago, ioa747 said: I agree with the array approach example: expandcollapse popup; https://www.autoitscript.com/forum/topic/210615-converting-string-into-a-variable-name/?do=findComment&comment=1521771 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <array.au3> Global $id = 0 ; active selection Global $aQuad[][] = [ _ ["X", "Y", "W", "H"], _ [100, 100, 200, 200], _ [200, 100, 300, 300], _ [500, 200, 800, 600], _ [300, 300, 1000, 700]] ;~ _ArrayDisplay($aQuad) While 1 Global $sInputBoxAnswer = InputBox("Which quadrant to show?", @CRLF & "Number only", $id + 1) Select Case @error = 0 ;OK - The string returned is valid ConsoleWrite("$sInputBoxAnswer=" & $sInputBoxAnswer & @CRLF) $id = Int($sInputBoxAnswer) If $id > 0 And $id <= UBound($aQuad) - 1 Then ConsoleWrite("X=" & $aQuad[$id][0] & ", ") ConsoleWrite("Y=" & $aQuad[$id][1] & ", ") ConsoleWrite("W=" & $aQuad[$id][2] & ", ") ConsoleWrite("H=" & $aQuad[$id][3] & @CRLF) MouseMove($aQuad[$id][0], $aQuad[$id][1]) ToolTip($aQuad[$id][0] & ", " & $aQuad[$id][1], $aQuad[$id][0], $aQuad[$id][1], "MouseMove XY") Sleep(500) MouseMove($aQuad[$id][2], $aQuad[$id][3]) ToolTip($aQuad[$id][2] & ", " & $aQuad[$id][3], $aQuad[$id][2], $aQuad[$id][3], "MouseMoveWH") EndIf Case @error = 1 ;The Cancel button was pushed Exit EndSelect Sleep(3000) ConsoleWrite("" & @CRLF) ToolTip("") WEnd I've been specifically avoiding Array's because I've spent the last month or so, at roughly 4 hours a day trying to understand them, and I still don't, so I don't think this is going to work for me. I appreciate the time you spent to write that, though. Link to comment Share on other sites More sharing options...
mistersquirrle Posted July 30, 2023 Share Posted July 30, 2023 Maybe you should start a thread asking about arrays to get someone to explain what it is that you don't understand about them. I usually find arrays easier to understand when you think about them just as a list, like $aArray[3] would just be: [0] - first item [1] - second item [2] - third item Or a 2d array would just be a list... of lists. So $aArray[3][3] would be: [0][#] [0][0] - first item, first sub [0][1] - first item, second sub [0][2] - first item, third sub [1][#] [1][0] - second item, first sub etc.... [2][#] [2][0] - third item, first sub etc... This type of layout basically it just repeated as you add more dimensions, so quickly $aArray[3][3][3] would look like: [0][#][#] [0][0][#] [0][0][0] - first item, first sub, first tertiary(?) Obviously arrays can start to get out of hand when you start adding a lot of dimensions, which is why a good way to keep track of things is to use variables with names that hold the indexes. For example using @ioa747s example: expandcollapse popup; https://www.autoitscript.com/forum/topic/210615-converting-string-into-a-variable-name/?do=findComment&comment=1521771 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <array.au3> Global $id = 0 ; active selection Global Enum $E_QUAD_X, $E_QUAD_Y, $E_QUAD_WIDTH, $E_QUAD_HEIGHT, $E_QUAD_MAX ; $E_QUAD_X = 0, $E_QUAD_Y = 1, etc. Global $aQuad[][$E_QUAD_MAX] = [ _ ["X", "Y", "W", "H"], _ [100, 100, 200, 200], _ [200, 100, 300, 300], _ [500, 200, 800, 600], _ [300, 300, 1000, 700]] ;~ _ArrayDisplay($aQuad) While 1 Global $sInputBoxAnswer = InputBox("Which quadrant to show?", @CRLF & "Number only", $id + 1) Select Case @error = 0 ;OK - The string returned is valid ConsoleWrite("$sInputBoxAnswer=" & $sInputBoxAnswer & @CRLF) $id = Int($sInputBoxAnswer) If $id > 0 And $id <= UBound($aQuad) - 1 Then ConsoleWrite("X=" & $aQuad[$id][$E_QUAD_X] & ", ") ConsoleWrite("Y=" & $aQuad[$id][$E_QUAD_Y] & ", ") ConsoleWrite("W=" & $aQuad[$id][$E_QUAD_WIDTH] & ", ") ConsoleWrite("H=" & $aQuad[$id][$E_QUAD_HEIGHT] & @CRLF) MouseMove($aQuad[$id][$E_QUAD_X], $aQuad[$id][$E_QUAD_Y]) ToolTip($aQuad[$id][$E_QUAD_X] & ", " & $aQuad[$id][$E_QUAD_Y], $aQuad[$id][$E_QUAD_X], $aQuad[$id][$E_QUAD_Y], "MouseMove XY") Sleep(500) MouseMove($aQuad[$id][$E_QUAD_WIDTH], $aQuad[$id][$E_QUAD_HEIGHT]) ToolTip($aQuad[$id][$E_QUAD_WIDTH] & ", " & $aQuad[$id][$E_QUAD_HEIGHT], $aQuad[$id][$E_QUAD_WIDTH], $aQuad[$id][$E_QUAD_HEIGHT], "MouseMoveWH") EndIf Case @error = 1 ;The Cancel button was pushed Exit EndSelect Sleep(3000) ConsoleWrite("" & @CRLF) ToolTip("") WEnd Now instead of just having indexes and not remembering that [0] is X and [3] is Height, you can just use the more descriptive variable names. Also, did you even try @Andreik's suggestion? Eval is exactly what you're looking for in your original question, if you don't want to use Arrays. However I would definitely recommend an Array over Eval. If neither of those options work, another option for you is Maps, in the latest version of AutoIt. Maps (or a Scripting Dictionary) are just like the example I gave with using the variables for the Array indexes, except you can use strings directly. So ioa747's example again, but with Maps (maybe not used very efficiently): expandcollapse popup; https://www.autoitscript.com/forum/topic/210615-converting-string-into-a-variable-name/?do=findComment&comment=1521771 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <array.au3> Global $sInputBoxAnswer Global $id = 0 ; active selection Global Enum $E_QUAD_X, $E_QUAD_Y, $E_QUAD_WIDTH, $E_QUAD_HEIGHT, $E_QUAD_MAX ; $E_QUAD_X = 0, $E_QUAD_Y = 1, etc. Global $mQuad[] ; Just like an Array declaration, except no size is given, signaling it's a map Global $mDimensions[] ; Another map that we'll put in our map $mQuad[1] = $mDimensions $mQuad[1]['X1'] = 100 $mQuad[1]['Y1'] = 100 $mQuad[1]['X2'] = 200 $mQuad[1]['Y2'] = 200 $mQuad[2] = $mDimensions $mQuad[2]['X1'] = 200 $mQuad[2]['Y1'] = 100 $mQuad[2]['X2'] = 300 $mQuad[2]['Y2'] = 300 $mQuad[3] = $mDimensions $mQuad[3]['X1'] = 500 $mQuad[3]['Y1'] = 200 $mQuad[3]['X2'] = 800 $mQuad[3]['Y2'] = 600 $mQuad[4] = $mDimensions $mQuad[4]['X1'] = 300 $mQuad[4]['Y1'] = 300 $mQuad[4]['X2'] = 1000 $mQuad[4]['Y2'] = 700 ;~ Global $aQuad[][$E_QUAD_MAX] = [ _ ;~ ["X", "Y", "W", "H"], _ ;~ [100, 100, 200, 200], _ ;~ [200, 100, 300, 300], _ ;~ [500, 200, 800, 600], _ ;~ [300, 300, 1000, 700]] ;~ _ArrayDisplay($aQuad) While 1 $sInputBoxAnswer = InputBox("Which quadrant to show?", @CRLF & "Number only", $id + 1) Select Case @error = 0 ;OK - The string returned is valid ConsoleWrite("$sInputBoxAnswer=" & $sInputBoxAnswer & @CRLF) $id = Int($sInputBoxAnswer) If MapExists($mQuad, $id) Then ConsoleWrite("X=" & $mQuad[$id]['X1'] & ", ") ConsoleWrite("Y=" & $mQuad[$id]['Y1'] & ", ") ConsoleWrite("W=" & $mQuad[$id]['X2'] & ", ") ConsoleWrite("H=" & $mQuad[$id]['Y2'] & @CRLF) MouseMove($mQuad[$id]['X1'], $mQuad[$id]['Y1']) ToolTip($mQuad[$id]['X1'] & ", " & $mQuad[$id]['Y1'], $mQuad[$id]['X1'], $mQuad[$id]['Y1'], "MouseMove XY") Sleep(500) MouseMove($mQuad[$id]['X2'], $mQuad[$id]['Y2']) ToolTip($mQuad[$id]['X2'] & ", " & $mQuad[$id]['Y2'], $mQuad[$id]['X2'], $mQuad[$id]['Y2'], "MouseMoveWH") Else EndIf Case @error = 1 ;The Cancel button was pushed Exit EndSelect Sleep(3000) ConsoleWrite("" & @CRLF) ToolTip("") WEnd I think that the main answer here for what you're looking to do is that Arrays are your best option, most likely. Of course personal preference will play a part, and someone else may say that SQLite is a better option (though you'll still have to go through Arrays a little bit as a middleman). Arrays are very important for the functionality of a lot of things, I definitely recommend spending some time writing some just test scripts using them, to understand them a little more. We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
JustCallMeAlec Posted August 2, 2023 Author Share Posted August 2, 2023 After a couple additional days of working at this, I may have finally figured it out. I appreciate all the suggestions. I think I've gone with the Array suggestion, even though the initial one was technically a solution, too. I'm about 25% of the way through the typing, but this is what I have thus far... expandcollapse popup; https://www.autoitscript.com/forum/topic/210615-converting-string-into-a-variable-name/?do=findComment&comment=1521771 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <array.au3> Global $id = 0 ; active selection Global $aQuad[][] = [ _ ["X1", "Y1", "X2", "Y2", "X3", "Y3", "X4", "Y4"], _ [223, 223, 325, 223, 223, 325, 325, 325], _ ;1 [325, 223, 450, 223, 325, 325, 450, 325], _ ;2 [450, 223, 550, 223, 450, 325, 550, 325], _ ;3 [550, 223, 650, 223, 550, 325, 650, 325], _ ;4 [650, 223, 750, 223, 650, 325, 750, 325], _ ;5 [750, 223, 850, 223, 750, 325, 850, 325], _ ;6 [850, 223, 950, 223, 850, 325, 950, 325], _ ;7 [950, 223, 1050, 223, 950, 325, 1050, 325], _ ;8 [1050, 223, 1150, 223, 1050, 325, 1150, 325], _ ;9 [1150, 223, 1250, 223, 1150, 325, 1250, 325], _ ;10 [223, 325, 325, 325, 223, 425, 325, 425], _ ;11 [325, 325, 450, 325, 325, 425, 450, 425], _ ;12 [450, 325, 550, 325, 450, 425, 550, 425], _ ;13 [550, 325, 650, 325, 550, 425, 650, 425], _ ;14 [650, 325, 750, 325, 650, 425, 750, 425], _ ;15 [750, 325, 850, 325, 750, 425, 850, 425], _ ;16 [850, 325, 950, 325, 850, 425, 950, 425], _ ;17 [950, 325, 1050, 325, 950, 425, 1050, 425], _ ;18 [1050, 325, 1150, 325, 1050, 425, 1150, 425], _ ;19 [1150, 325, 1250, 325, 1150, 425, 1250, 425], _ ;20 [223, 425, 325, 425, 223, 525, 325, 525], _ ;21 [325, 425, 450, 425, 325, 525, 450, 525], _ ;22 [450, 425, 550, 425, 450, 525, 550, 525], _ ;23 [550, 425, 650, 425, 550, 525, 650, 525], _ ;24 [650, 425, 750, 425, 650, 525, 750, 525], _ ;25 [750, 425, 850, 425, 750, 525, 850, 525], _ ;26 [850, 425, 950, 425, 850, 525, 950, 525], _ ;27 [950, 425, 1050, 425, 950, 525, 1050, 525], _ ;28 [1050, 425, 1150, 425, 1050, 525, 1150, 525], _ ;29 [1150, 425, 1250, 425, 1150, 525, 1250, 525], _ ;30 [223, 525, 325, 525, 223, 625, 325, 625], _ ;31 [325, 525, 450, 525, 325, 625, 450, 625], _ ;32 [450, 525, 550, 525, 450, 625, 550, 625], _ ;33 [550, 525, 650, 525, 550, 625, 650, 625], _ ;34 [650, 525, 750, 525, 650, 625, 750, 625], _ ;35 [750, 525, 850, 525, 750, 625, 850, 625], _ ;36 [850, 525, 950, 525, 850, 625, 950, 625], _ ;37 [950, 525, 1050, 525, 950, 625, 1050, 625], _ ;38 [1050, 525, 1150, 525, 1050, 625, 1150, 625], _ ;39 [1150, 525, 1250, 525, 1150, 625, 1250, 625]] ;40 ;[x1, y1, x2, y2, x3, 625, x4, 625], _ ;[-1, -1, -1, -1, -1, -1, -1, -1]] ;~ _ArrayDisplay($aQuad) While 1 Global $sInputBoxAnswer = InputBox("Which quadrant to show?", @CRLF & "Number only", $id + 1) Select Case @error = 0 ;OK - The string returned is valid $id = Int($sInputBoxAnswer) If $id > 0 And $id <= UBound($aQuad) Then MouseMove($aQuad[$id][0], $aQuad[$id][1], 1) ToolTip($aQuad[$id][0] & ", " & $aQuad[$id][1], $aQuad[$id][0], $aQuad[$id][1], "Mouse X1 Y1") Sleep(250) MouseMove($aQuad[$id][2], $aQuad[$id][3], 1) ToolTip($aQuad[$id][2] & ", " & $aQuad[$id][3], $aQuad[$id][2], $aQuad[$id][3], "Mouse X2 Y2") Sleep(250) MouseMove($aQuad[$id][4], $aQuad[$id][5], 1) ToolTip($aQuad[$id][4] & ", " & $aQuad[$id][5], $aQuad[$id][4], $aQuad[$id][5], "Mouse X3 625") Sleep(250) MouseMove($aQuad[$id][6], $aQuad[$id][7], 1) ToolTip($aQuad[$id][6] & ", " & $aQuad[$id][7], $aQuad[$id][6], $aQuad[$id][7], "Mouse X4 625") Sleep(250) EndIf Case @error = 1 ;The Cancel button was pushed Exit EndSelect ;Sleep(350) ToolTip("") WEnd As an FYI, the comments on each line counting from 1 to currently 40 are the box quadrants I need to map. I've got about 30 to go! Wish me luck, and again, I appreciate the replies. Link to comment Share on other sites More sharing options...
mistersquirrle Posted August 2, 2023 Share Posted August 2, 2023 If you're on a roll then you're on a roll. Sometimes just completing the task is better than finding the most optimal way. However that being said, you are definitely doing more typing/work than needed for your X1-Y4 pairs. You're providing each corner of a rectangle, even though you only need opposing corners (like top left and bottom right). For example: ; https://www.autoitscript.com/forum/topic/210615-converting-string-into-a-variable-name/?do=findComment&comment=1521771 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <array.au3> Global $id = 0 ; active selection Global $aQuad[][] = [ _ ; Provide coordinates in groups, [Top Left] and [Bottom Right] ["X1", "Y1", "X2", "Y2"], _ [223, 223, 325, 325], _ ;1 [750, 425, 850, 525] _ ;26 ] While 1 Global $sInputBoxAnswer = InputBox("Which quadrant to show?", @CRLF & "Number only, 0 - " & UBound($aQuad) - 1, $id + 1) If @error Then Exit $id = Int($sInputBoxAnswer) If $id < 0 Or $id >= UBound($aQuad) Then ConsoleWrite('Invalid number' & @CRLF) ContinueLoop EndIf For $iY = 1 To 3 Step 2 For $iX = 0 To 2 Step 2 MouseMove($aQuad[$id][$iX], $aQuad[$id][$iY], 1) ToolTip($aQuad[$id][$iX] & ", " & $aQuad[$id][$iY], _ $aQuad[$id][$iX] + 20, _ ; offset so we can see the whole tooltip without the mouse in the way $aQuad[$id][$iY], _ 'X' & ($iX + 2) / 2 & ', Y' & ($iY + 1) / 2) Sleep(250) Next Next ;Sleep(350) ToolTip("") WEnd Here, we're only using X1,Y1 and X2,Y2. These points are the Top Left and Bottom Right coordinates, that's all we need to make a rectangle. That'll save you half the typing for coordinates. I also simplified the main loop, and swapped having 4 mouse moves to a couple of loops. If you wanted to keep that part expanded though, here's what that would look like: MouseMove($aQuad[$id][0], $aQuad[$id][1], 1) ToolTip($aQuad[$id][0] & ", " & $aQuad[$id][1], $aQuad[$id][0], $aQuad[$id][1], "Top left") Sleep(250) MouseMove($aQuad[$id][2], $aQuad[$id][1], 1) ToolTip($aQuad[$id][2] & ", " & $aQuad[$id][1], $aQuad[$id][2], $aQuad[$id][1], "Top right") Sleep(250) MouseMove($aQuad[$id][0], $aQuad[$id][3], 1) ToolTip($aQuad[$id][0] & ", " & $aQuad[$id][3], $aQuad[$id][0], $aQuad[$id][3], "Bottom left") Sleep(250) MouseMove($aQuad[$id][2], $aQuad[$id][3], 1) ToolTip($aQuad[$id][2] & ", " & $aQuad[$id][3], $aQuad[$id][2], $aQuad[$id][3], "Bottom right") Sleep(250) The nice part with not having each one as its own thing is that if you want to change a part of it, instead of changing it 4 places it's only 1. Also I noticed that your coordinates are almost a pattern, at least besides the first 1 or 2 points of the pattern. But, would something like this work? expandcollapse popup; https://www.autoitscript.com/forum/topic/210615-converting-string-into-a-variable-name/?do=findComment&comment=1521771 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <array.au3> Global $id = 0 ; active selection Global $sInputBoxAnswer Global $aiCoords[2] While 1 $sInputBoxAnswer = InputBox("Which quadrant to show?", @CRLF & "Number only", $id + 1) If @error Then Exit $id = Int($sInputBoxAnswer) If $id <= 0 Then ConsoleWrite('Invalid number' & @CRLF) ContinueLoop EndIf For $iY = 0 To 1 $aiCoords[1] = 225 + (100 * (Floor($id / 10) + $iY)) For $iX = 0 To 1 $aiCoords[0] = 250 + (100 * Mod(($id - 1) + $iX, 10)) MouseMove($aiCoords[0], $aiCoords[1], 1) ToolTip(String($aiCoords[0]) & ", " & String($aiCoords[1]), _ $aiCoords[0] + 20, _ ; offset so we can see the whole tooltip without the mouse in the way $aiCoords[1], _ 'X' & ($iX + 1) & ', Y' & ($iY + 1)) Sleep(250) If $iX = $iY Then ConsoleWrite('id: ' & $id & ' X' & $iX & ',Y' & $iY & ': ' & _ String($aiCoords[0]) & ", " & String($aiCoords[1]) & @CRLF) Next Next ;Sleep(350) ToolTip("") WEnd This assumes that you start at 250 instead of 223, and also hit 350 instead of 335. Everything else just seems to be multiples of 100, with 10 points in X before moving to a new Y and repeating. I think I had some other stuff to say, but then took a work meeting and forgot. Let me know if you have questions. Musashi, mikell and JustCallMeAlec 2 1 We ought not to misbehave, but we should look as though we could. Link to comment Share on other sites More sharing options...
JustCallMeAlec Posted August 15, 2023 Author Share Posted August 15, 2023 On 8/2/2023 at 1:50 PM, mistersquirrle said: If you're on a roll then you're on a roll. Sometimes just completing the task is better than finding the most optimal way. However that being said, you are definitely doing more typing/work than needed for your X1-Y4 pairs. You're providing each corner of a rectangle, even though you only need opposing corners (like top left and bottom right). For example: ; https://www.autoitscript.com/forum/topic/210615-converting-string-into-a-variable-name/?do=findComment&comment=1521771 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <array.au3> Global $id = 0 ; active selection Global $aQuad[][] = [ _ ; Provide coordinates in groups, [Top Left] and [Bottom Right] ["X1", "Y1", "X2", "Y2"], _ [223, 223, 325, 325], _ ;1 [750, 425, 850, 525] _ ;26 ] While 1 Global $sInputBoxAnswer = InputBox("Which quadrant to show?", @CRLF & "Number only, 0 - " & UBound($aQuad) - 1, $id + 1) If @error Then Exit $id = Int($sInputBoxAnswer) If $id < 0 Or $id >= UBound($aQuad) Then ConsoleWrite('Invalid number' & @CRLF) ContinueLoop EndIf For $iY = 1 To 3 Step 2 For $iX = 0 To 2 Step 2 MouseMove($aQuad[$id][$iX], $aQuad[$id][$iY], 1) ToolTip($aQuad[$id][$iX] & ", " & $aQuad[$id][$iY], _ $aQuad[$id][$iX] + 20, _ ; offset so we can see the whole tooltip without the mouse in the way $aQuad[$id][$iY], _ 'X' & ($iX + 2) / 2 & ', Y' & ($iY + 1) / 2) Sleep(250) Next Next ;Sleep(350) ToolTip("") WEnd Here, we're only using X1,Y1 and X2,Y2. These points are the Top Left and Bottom Right coordinates, that's all we need to make a rectangle. That'll save you half the typing for coordinates. I also simplified the main loop, and swapped having 4 mouse moves to a couple of loops. If you wanted to keep that part expanded though, here's what that would look like: MouseMove($aQuad[$id][0], $aQuad[$id][1], 1) ToolTip($aQuad[$id][0] & ", " & $aQuad[$id][1], $aQuad[$id][0], $aQuad[$id][1], "Top left") Sleep(250) MouseMove($aQuad[$id][2], $aQuad[$id][1], 1) ToolTip($aQuad[$id][2] & ", " & $aQuad[$id][1], $aQuad[$id][2], $aQuad[$id][1], "Top right") Sleep(250) MouseMove($aQuad[$id][0], $aQuad[$id][3], 1) ToolTip($aQuad[$id][0] & ", " & $aQuad[$id][3], $aQuad[$id][0], $aQuad[$id][3], "Bottom left") Sleep(250) MouseMove($aQuad[$id][2], $aQuad[$id][3], 1) ToolTip($aQuad[$id][2] & ", " & $aQuad[$id][3], $aQuad[$id][2], $aQuad[$id][3], "Bottom right") Sleep(250) The nice part with not having each one as its own thing is that if you want to change a part of it, instead of changing it 4 places it's only 1. Also I noticed that your coordinates are almost a pattern, at least besides the first 1 or 2 points of the pattern. But, would something like this work? expandcollapse popup; https://www.autoitscript.com/forum/topic/210615-converting-string-into-a-variable-name/?do=findComment&comment=1521771 #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 #include <array.au3> Global $id = 0 ; active selection Global $sInputBoxAnswer Global $aiCoords[2] While 1 $sInputBoxAnswer = InputBox("Which quadrant to show?", @CRLF & "Number only", $id + 1) If @error Then Exit $id = Int($sInputBoxAnswer) If $id <= 0 Then ConsoleWrite('Invalid number' & @CRLF) ContinueLoop EndIf For $iY = 0 To 1 $aiCoords[1] = 225 + (100 * (Floor($id / 10) + $iY)) For $iX = 0 To 1 $aiCoords[0] = 250 + (100 * Mod(($id - 1) + $iX, 10)) MouseMove($aiCoords[0], $aiCoords[1], 1) ToolTip(String($aiCoords[0]) & ", " & String($aiCoords[1]), _ $aiCoords[0] + 20, _ ; offset so we can see the whole tooltip without the mouse in the way $aiCoords[1], _ 'X' & ($iX + 1) & ', Y' & ($iY + 1)) Sleep(250) If $iX = $iY Then ConsoleWrite('id: ' & $id & ' X' & $iX & ',Y' & $iY & ': ' & _ String($aiCoords[0]) & ", " & String($aiCoords[1]) & @CRLF) Next Next ;Sleep(350) ToolTip("") WEnd This assumes that you start at 250 instead of 223, and also hit 350 instead of 335. Everything else just seems to be multiples of 100, with 10 points in X before moving to a new Y and repeating. I think I had some other stuff to say, but then took a work meeting and forgot. Let me know if you have questions. Will do. I think I've got it working the way I had intended, I'm now working on prioritizing certain loops over other loops, and then making some loops used in certain situations, but I'll make a new post as it'll be a whole different ball game by that point. I again really appreciate the replies. 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