two loop parse help

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
theon
Posts: 124
Joined: 23 Jun 2019, 15:39

two loop parse help

13 Apr 2022, 20:08

hello everyone how do I apply both loop parse in loop field?

Code: Select all

F1::
Images =
(LTrim
1
2
3
4
5
6
7
)

ImageNumberFound = 0
Images2 =
(LTrim
12
22
32
42
52
62
72
)
ImageNumberFound2 = 0

loop{
Loop, Parse, Images, `n, `r
Loop, Parse, Images2, `n, `r
{

      {
         ImageFound := A_LoopField
         ImageNumberFound:= A_Index
      }
	        {
         ImageFound2 := A_LoopField2
         ImageNumberFound2:= A_Index2
      }
    
	MsgBox, %ImageFound%
	MsgBox, %ImageFound2%
	}}
return


Last edited by theon on 14 Apr 2022, 12:28, edited 1 time in total.
User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: two loop parse help

13 Apr 2022, 20:17

Code: Select all

F1::
Images =
(LTrim
1
2
3
4
5
6
7
)

ImageNumberFound = 0
Images2 =
(LTrim
12
22
32
42
52
62
72
)
ImageNumberFound2 = 0

loop
{
	loop, Parse, Images, `n, `r
	{
		OuterLoopField := A_LoopField
		OuterIndex := A_Index
		loop, Parse, Images2, `n, `r
		{
			ImageFound := OuterLoopField
			ImageNumberFound:= OuterIndex
			ImageFound2 := A_LoopField
			ImageNumberFound2:= A_Index
			
			MsgBox, %ImageFound%
			MsgBox, %ImageFound2%
		}
	}
}
return
theon
Posts: 124
Joined: 23 Jun 2019, 15:39

Re: two loop parse help

13 Apr 2022, 20:41

boiler wrote:
13 Apr 2022, 20:17

Code: Select all

F1::
Images =
(LTrim
1
2
3
4
5
6
7
)

ImageNumberFound = 0
Images2 =
(LTrim
12
22
32
42
52
62
72
)
ImageNumberFound2 = 0

loop
{
	loop, Parse, Images, `n, `r
	{
		OuterLoopField := A_LoopField
		OuterIndex := A_Index
		loop, Parse, Images2, `n, `r
		{
			ImageFound := OuterLoopField
			ImageNumberFound:= OuterIndex
			ImageFound2 := A_LoopField
			ImageNumberFound2:= A_Index
			
			MsgBox, %ImageFound%  %ImageFound2%

		}
	}
}
return
it worked but he sends the two together and then sends them separately, is there a way to send the two together?

Code: Select all

1 12 next 2 22 next 3 32
User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: two loop parse help

13 Apr 2022, 21:37

Then you don't really want nested loops. You want to step through both in the same loop:

Code: Select all

F1::
Images =
(LTrim
1
2
3
4
5
6
7
)

ImageNumberFound = 0
Images2 =
(LTrim
12
22
32
42
52
62
72
)

ImageArray := StrSplit(Images, "`n", "`r")
ImageArray2 := StrSplit(Images2, "`n", "`r")

for Index, Image in ImageArray
	MsgBox, % Image " "  ImageArray2[Index]
return
User avatar
flyingDman
Posts: 2848
Joined: 29 Sep 2013, 19:01

Re: two loop parse help

13 Apr 2022, 21:42

This might be an easier way:

Code: Select all

Images =
(LTrim
1
2
3
4
5
6
7
)
Images2 =
(LTrim
12
22
32
42
52
62
72
)

for a,b in x:= strsplit(images,"`n","`r")
	msgbox % b "`n" strsplit(images2,"`n","`r")[a]
Edit: sorry did not see @boiler 's last post. Same wavelength...
14.3 & 1.3.7
theon
Posts: 124
Joined: 23 Jun 2019, 15:39

Re: two loop parse help

13 Apr 2022, 21:47

boiler wrote:
13 Apr 2022, 21:37
Then you don't really want nested loops. You want to step through both in the same loop:

Code: Select all

F1::
Images =
(LTrim
1
2
3
4
5
6
7
)

ImageNumberFound = 0
Images2 =
(LTrim
12
22
32
42
52
62
72
)

ImageArray := StrSplit(Images, "`n", "`r")
ImageArray2 := StrSplit(Images2, "`n", "`r")

for Index, Image in ImageArray
	MsgBox, % Image " "  ImageArray2[Index]
return
I want them to be aligned img and img2
to apply here
but it's going too fast when I try to apply sleep doesn't work

Code: Select all

Images =
(LTrim
 %Contentsx%
)
ImageNumberFound = 0

Images2 =
(LTrim
%Contentsy%
)
ImageNumberFound2 = 0

loop{

loop, Parse, Images, `n, `r
	loop, Parse, Images2, `n, `r
	{

		OuterLoopField := A_LoopField
		OuterIndex := A_Index
	
		
			ImageFound := OuterLoopField
			ImageNumberFound:= OuterIndex
			ImageFound2 := A_LoopField
			ImageNumberFound2:= A_Index2

	 posxx := mem.write(addressmana + 0x168 ,ImageFound, "int")

     posyy := mem.write(addressmana + 0x16c ,ImageFound2, "int")



		}

}

return
User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: two loop parse help

13 Apr 2022, 22:18

They are aligned. You don’t understand the code and must not have run it. It does exactly what you said you wanted.

You applied the wrong one. You went back to the nested one. Notice that the one you just posted looks nothing like the one you quoted.
theon
Posts: 124
Joined: 23 Jun 2019, 15:39

Re: two loop parse help

13 Apr 2022, 22:25

boiler wrote:
13 Apr 2022, 22:18
They are aligned. You don’t understand the code and must not have run it. It does exactly what you said you wanted.

You applied the wrong one. You went back to the nested one. Notice that the one you just posted looks nothing like the one you quoted.

I'm trying like this to see if it's right

Code: Select all

F1::
Images =
(LTrim
6208
5888
6144
6976
)
ImageNumberFound = 0

Images2 =
(LTrim
4896
4320
3840
5088
)
ImageNumberFound2 = 0

loop{

loop, Parse, Images, `n, `r
	loop, Parse, Images2, `n, `r
	{

sleep, 1000
		OuterLoopField := A_LoopField
		OuterIndex := A_Index
	
		
			ImageFound := OuterLoopField
			ImageNumberFound:= OuterIndex
			ImageFound2 := A_LoopField
			ImageNumberFound2:= A_Index2

	

	 


		
	 posxx := mem.write(addressmana + 0x168 ,ImageFound, "int")

     posyy := mem.write(addressmana + 0x16c ,ImageFound2, "int")
}
}

return
User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: two loop parse help

13 Apr 2022, 22:44

Once again, you are applying the wrong version for what you ended up saying you wanted. Why did you post a version with a nested loop again?
theon
Posts: 124
Joined: 23 Jun 2019, 15:39

Re: two loop parse help

14 Apr 2022, 12:22

boiler wrote:
13 Apr 2022, 22:44
Once again, you are applying the wrong version for what you ended up saying you wanted. Why did you post a version with a nested loop again?
Sorry for the delay, I'm trying to put the images and images2 values in us, how would you do it?
posxx := mem.write(addressmana + 0x168 ,ImageFound, "int")
posyy := mem.write(addressmana + 0x16c ,ImageFound2, "int")

Code: Select all

F1::
Images =
(LTrim
1
2
3
4
5
6
7
)

ImageNumberFound = 0
Images2 =
(LTrim
12
22
32
42
52
62
72
)

ImageArray := StrSplit(Images, "`n", "`r")
ImageArray2 := StrSplit(Images2, "`n", "`r")

for Index, Image in ImageArray
	MsgBox, % Image " "  ImageArray2[Index]
	 posxx := mem.write(addressmana + 0x168 ,Images, "int")
     posyy := mem.write(addressmana + 0x16c ,Images2, "int")
return
User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: two loop parse help

14 Apr 2022, 12:52

There are a few issues to fix. See the comments in the code below:

Code: Select all

F1::
Images =
(LTrim
1
2
3
4
5
6
7
)

ImageNumberFound = 0
Images2 =
(LTrim
12
22
32
42
52
62
72
)

ImageArray := StrSplit(Images, "`n", "`r")
ImageArray2 := StrSplit(Images2, "`n", "`r")

 ; need to define a code block.  Indenting means nothing to AHK!  It's for our readability only.  You were looping only on the MsgBox line, not the mem.write lines
for Index, Image in ImageArray { ; "{" to mark start code block
	MsgBox, % Image " "  ImageArray2[Index]
	posxx := mem.write(addressmana + 0x168 ,Image, "int") ; Image is this particular element of ImageArray as defined by the "for" loop (not Images like you had it)
	posyy := mem.write(addressmana + 0x16c ,ImageArray2[Index], "int") ; ImageArray2[Index] is this particular element of ImageArray2 (not Images2 like you had it)
	; we use ImageArray2[Index] for the second array because the "for" loop is only enumerating the first array, but we can identify the particular element of the second array this way
} ; mark end of code block
return
theon
Posts: 124
Joined: 23 Jun 2019, 15:39

Re: two loop parse help

16 Apr 2022, 15:36

boiler wrote:
14 Apr 2022, 12:52
There are a few issues to fix. See the comments in the code below:

Code: Select all

F1::
Images =
(LTrim
1
2
3
4
5
6
7
)

ImageNumberFound = 0
Images2 =
(LTrim
12
22
32
42
52
62
72
)

ImageArray := StrSplit(Images, "`n", "`r")
ImageArray2 := StrSplit(Images2, "`n", "`r")

 ; need to define a code block.  Indenting means nothing to AHK!  It's for our readability only.  You were looping only on the MsgBox line, not the mem.write lines
for Index, Image in ImageArray { ; "{" to mark start code block
	MsgBox, % Image " "  ImageArray2[Index]
	posxx := mem.write(addressmana + 0x168 ,Image, "int") ; Image is this particular element of ImageArray as defined by the "for" loop (not Images like you had it)
	posyy := mem.write(addressmana + 0x16c ,ImageArray2[Index], "int") ; ImageArray2[Index] is this particular element of ImageArray2 (not Images2 like you had it)
	; we use ImageArray2[Index] for the second array because the "for" loop is only enumerating the first array, but we can identify the particular element of the second array this way
} ; mark end of code block
return
sorry, but my level is too big to understand this.
User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: two loop parse help

16 Apr 2022, 17:48

OK. No need to apologize to me. I don't know what else you want me to do after modifying the code and explaining it. You can ask further questions if you want. If you're saying that you don't want to try to understand it because it's too difficult for you, then I guess we're done here.
theon
Posts: 124
Joined: 23 Jun 2019, 15:39

Re: two loop parse help

16 Apr 2022, 17:54

boiler wrote:
16 Apr 2022, 17:48
OK. No need to apologize to me. I don't know what else you want me to do after modifying the code and explaining it. You can ask further questions if you want. If you're saying that you don't want to try to understand it because it's too difficult for you, then I guess we're done here.
I think the point is not trying to understand, but not being able to explain what I wanted to you. Thank you.
theon
Posts: 124
Joined: 23 Jun 2019, 15:39

Re: two loop parse help

28 Apr 2022, 07:34

boiler wrote:
16 Apr 2022, 17:48
OK. No need to apologize to me. I don't know what else you want me to do after modifying the code and explaining it. You can ask further questions if you want. If you're saying that you don't want to try to understand it because it's too difficult for you, then I guess we're done here.
could it be like this?

Code: Select all


Images =
(LTrim
1
2
3
4
5
6
7
)
Images2 =
(LTrim
12
22
32
42
52
62
72
)

ImageArray := StrSplit(Images, "`n", "`r")
ImageArray2 := StrSplit(Images2, "`n", "`r")

for Index, Image in ImageArray
	x:= % Image " "  y:= ImageArray2[Index]
	
	
	gosub, show_it ;~8


	
		}

return

show_it:

{

	 posx := mem.write(addressmana + 0x168 ,x, "int")
     posy := mem.write(addressmana + 0x16c ,y, "int")
	 

  }
return
or

Code: Select all

loop
{

ImageArray := StrSplit(Images, "`n", "`r")
ImageArray2 := StrSplit(Images2, "`n", "`r")

for Index, Image in ImageArray
 mem.write(addressmana + 0x168 ,Image, "int") " " mem.write(addressmana + 0x16c ,ImageArray2[Index], "int") 


		}
User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: two loop parse help

28 Apr 2022, 07:58

There are a few things wrong with this:

Code: Select all

for Index, Image in ImageArray
	x:= % Image " "  y:= ImageArray2[Index]
	
	
	gosub, show_it ;~8


	
		}
Try this:

Code: Select all

for Index, Image in ImageArray
{ ; this was missing
	x := Image ; no % and putting " " between them doesn't make sense
	y := ImageArray2[Index]
	
	gosub, show_it ;~8
}

But that doesn't accomplish anything different than what I showed in my code. You just moved some of the lines to a subroutine and assigned other variable names that wouldn't be necessary.
User avatar
boiler
Posts: 17384
Joined: 21 Dec 2014, 02:44

Re: two loop parse help

28 Apr 2022, 08:03

theon wrote:

Code: Select all

loop
{

ImageArray := StrSplit(Images, "`n", "`r")
ImageArray2 := StrSplit(Images2, "`n", "`r")

for Index, Image in ImageArray
 mem.write(addressmana + 0x168 ,Image, "int") " " mem.write(addressmana + 0x16c ,ImageArray2[Index], "int") 


		}
What's the purpose of the outer loop? That doesn't make sense. And the " " in between the two lines again doesn't make sense. And once again, it looks like you are just trying to accomplish what my code already did. Did you even try it? Everything you're showing is just a messed up version of that.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], JnLlnd and 201 guests