Help storing calculations in Array Topic is solved

Ask gaming related questions (AHK v1.1 and older)
simplescripts
Posts: 2
Joined: 18 May 2022, 13:09

Help storing calculations in Array

Post by simplescripts » 18 May 2022, 14:15

I'm making a trainer, I need to calculate some data about the game window, then store that into an Array
Seems simple enough, but at the end of the loop all the elements of the array are the same, even though they are not calculated that way..

Here is an example that will produce the issue

Code: Select all

rows := [[]]
Loop 8 {
  rows[%A_Index%] := [ 30, 50 + ( 1000 / 8 * (A_Index-1) ), 150, 45 ]

  MsgBox, % " x: " rows[%A_Index%][1] " y: " rows[%A_Index%][2] " w: " rows[%A_Index%][3] " h: " rows[%A_Index%][4]
}
Loop 8 {
  MsgBox, % " x: " rows[%A_Index%][1] " y: " rows[%A_Index%][2] " w: " rows[%A_Index%][3] " h: " rows[%A_Index%][4]
}
The first series of MsgBoxs' will each show a different number for " y: "
The second series of MsgBoxs' will each show the same number for " y: " , why?

The "y" (2nd item) of each row ends up being the same for all row indices, even though to me it seems like they should differ as printed by the first MsgBox series
What could I do to properly store calculations into an Array?

User avatar
flyingDman
Posts: 2791
Joined: 29 Sep 2013, 19:01

Re: Help storing calculations in Array  Topic is solved

Post by flyingDman » 18 May 2022, 14:40

Try something like:

Code: Select all

rows := []
Loop 8
  rows.push([30, 50 + ( 1000 / 8 * (A_Index-1) ), 150, 45])

for x,y in rows
	msgbox % y.1 " " y.2 " " y.3 " " y.4
14.3 & 1.3.7

simplescripts
Posts: 2
Joined: 18 May 2022, 13:09

Re: Help storing calculations in Array

Post by simplescripts » 18 May 2022, 15:11

flyingDman wrote:
18 May 2022, 14:40
Try something like:

Code: Select all

rows := []
Loop 8
  rows.push([30, 50 + ( 1000 / 8 * (A_Index-1) ), 150, 45])

for x,y in rows
	msgbox % y.1 " " y.2 " " y.3 " " y.4
Thanks, I was having the same issue with Push before too. Not sure what I was doing wrong but it works now |:)

Post Reply

Return to “Gaming Help (v1)”