• 0

# increment index number

## Question

Hello.
Keep getting error.
Not able to increment index number from in a table.

This not work, error during incrementing.
error: attempt to index ? (a nil value) with key 'value' (field '?')

```a = gg.getListItems()
total = gg.getResultsCount(a) / 2

loop = 1

while (loop <= total) do

for i = 1, #x do
x[i].value = x[loop].value
end
gg.setValues(x)

for i = 1, #z do
z[i].value = z[loop].value
end
gg.setValues(z)

gg.sleep(500)

loop = loop + 1

end```

If i don't try incrementing the index number by 1, the loop keeps iterating over the same elements at the given index...index number 1.
Script should basically do this:

```  for i = 1, #x do
x[i].value = x[1].value
end
gg.setValues(x)

for i = 1, #z do
z[i].value = z[1].value
end
gg.setValues(z)

for i = 1, #x do
x[i].value = x[2].value
end
gg.setValues(x)

for i = 1, #z do
z[i].value = z[2].value
end
gg.setValues(z)

for i = 1, #x do
x[i].value = x[3].value
end
gg.setValues(x)

for i = 1, #z do
z[i].value = z[3].value
end
gg.setValues(z)```

till it iterate over all the results. of both the tables x and z.
incrimination of index number must be based on the total amount of results from the result Count divided by two.

Edited by XxhentaixX

## Recommended Posts

• 0

I want to ask where the value of z and y is obtained, as far as I can see, you only get the result from a

##### Share on other sites

• 0
```gg.searchNumber('', gg.TYPE_FLOAT)
gg.refineNumber('', gg.TYPE_FLOAT)
local count = gg.getResultsCount()
local results = gg.getResults(count)

local x = {}
for i = 1, count, 1 do
for j = 1, 50 do
end
end

gg.removeListItems(x)
gg.refineNumber('0', gg.TYPE_FLOAT, false, gg.SIGN_NOT_EQUAL)
x = gg.getResults(20)
gg.clearResults()

local z = {}
for i = 1, count, 1 do
for j = 1, 50 do
end
end

gg.removeListItems(z)
gg.refineNumber('0', gg.TYPE_FLOAT, false, gg.SIGN_NOT_EQUAL)
z = gg.getResults(20)
gg.clearResults()

a = gg.getListItems()
total = gg.getResultsCount(a) / 2

loop = 1

while (loop <= total) do

for i = 1, #x do
x[i].value = x[loop].value
end
gg.setValues(x)

for i = 1, #z do
z[i].value = z[loop].value
end
gg.setValues(z)

gg.sleep(500)

loop = loop + 1

end```
4 hours ago, TisNquyen said:

I want to ask where the value of z and y is obtained, as far as I can see, you only get the result from a

x and z are two tables from a previous search.

(Note: x and z have the same amount of results.)

Both results are saved in the save list.

I add all the elements in the saved list in a new table using "a" as the variable.

Load them in the results list for get the count and divide the amount by two.

Variable name "loop" is equal to 1 and is later used for reference as index number for the indexed arrays from the tables x and z

The loop value which is also the index number "x[loop].value" and "z[loop].value" should add 1 at each round till it is equal to the count value of "total"

"x[i].value = x[loop].value" will edit all the values in table x equal to the value of the first result in x.

"y[i].value = y[loop].value" will edit all the values in table y equal to the value of the first result in y.

Round one is finished, increment loop by one. So loop should equal two by now.

So in theory it should do this next:

"x[i].value = x[loop].value" will edit all the values in table x equal to the value of the second result in x.

"y[i].value = y[loop].value" will edit all the values in table y equal to the value of the second result in y.

...etc

Edited by XxhentaixX
Full script
##### Share on other sites

• 0
```for j = 1, 50 do
end```

here, even if you have 50 more results, you will only get 1 result in x and y

##### Share on other sites

• 0
```gg.searchNumber('', gg.TYPE_FLOAT)
gg.refineNumber('', gg.TYPE_FLOAT)
local count = gg.getResultsCount()
local res = gg.getResults(count)

local x, y = {}, {}
local xChecker, yChecker = {}, {}

--get values at offset 0x44 and 0x4c
for i, v in ipairs(res) do
end
xChecker, yChecker = gg.getValues(xChecker), gg.getValues(yChecker)

--put addresses with value zero into table x and y
for i, v in ipairs(xChecker) do
if v.value==0 then x[#x+1] = xChecker[i] end
if yChecker[i].value==0 then y[#y+1] = yChecker[i] end
end

--check if the result amount of x and y are equal
if #x~=#y then return print('Ohh the results of x and y are not equal. check maually please') end

--loop
local total = #x+#y
for loop=1, total/2 do
for i, v in ipairs(x) do
v.value=x[loop].value
end
gg.setValues(x)

for i, v in ipairs(y) do
v.value=y[loop].value
end
gg.setValues(y)
gg.sleep(500)
end```

i dont understand the loop part what you want to do.

##### Share on other sites

• 0

```gg.searchNumber('', gg.TYPE_FLOAT)
gg.refineNumber('', gg.TYPE_FLOAT)
local count = gg.getResultsCount()
local results = gg.getResults(count)

local _x, _y = {}, {}
for i, v in ipairs(results) do
end
_x, _y = gg.getValues(_x), gg.getValues(_y)

local x, y = {}
for i, v in ipairs(_x) do
if _x[i].value ~= '0' then
table.insert(x, x[i])
end
if _y[i].value ~= '0' then
table.insert(y, y[i])
end
end

if #x ~= #y then
return print "the results from x and y may not be the same!"
end

for loop = 1, #x do
for i, v in ipairs(x) do
x[i].value = x[loop].value
end
gg.setValues(x)
for i, v in ipairs(z) do
z[i].value = z[loop].value
end
gg.setValues(z)
gg.sleep(500)
end```

Edited by TisNquyen
##### Share on other sites

• 0
2 hours ago, TisNquyen said:

```gg.searchNumber('', gg.TYPE_FLOAT)
gg.refineNumber('', gg.TYPE_FLOAT)
local count = gg.getResultsCount()
local results = gg.getResults(count)

local _x, _y = {}, {}
for i, v in ipairs(results) do
end
_x, _y = gg.getValues(_x), gg.getValues(_y)

local x, y = {}
for i, v in ipairs(_x) do
if _x[i].value ~= '0' then
table.insert(x, x[i])
end
if _y[i].value ~= '0' then
table.insert(y, y[i])
end
end

if #x ~= #y then
return print "the results from x and y may not be the same!"
end

for loop = 1, #x do
for i, v in ipairs(x) do
x[i].value = x[loop].value
end
gg.setValues(x)
for i, v in ipairs(z) do
z[i].value = z[loop].value
end
gg.setValues(z)
gg.sleep(500)
end```

##### Share on other sites

• 0
1 minute ago, XxhentaixX said:

Change _z to _y

##### Share on other sites

• 0
2 hours ago, Lover1500 said:
` `

i dont understand the loop part what you want to do.

The loop has to shorten this behavior:

```for i = 1, #x do
x[i].value = x[1].value
end
gg.setValues(x)

for i = 1, #z do
z[i].value = z[1].value
end
gg.setValues(z)

for i = 1, #x do
x[i].value = x[2].value
end
gg.setValues(x)

for i = 1, #z do
z[i].value = z[2].value
end
gg.setValues(z)

for i = 1, #x do
x[i].value = x[3].value
end
gg.setValues(x)

for i = 1, #z do
z[i].value = z[3].value
end
gg.setValues(z)```

Edited by XxhentaixX
##### Share on other sites

• 0
8 minutes ago, TisNquyen said:

Change _z to _y

##### Share on other sites

• 0
```gg.searchNumber('', gg.TYPE_FLOAT)
gg.refineNumber('', gg.TYPE_FLOAT)
local count = gg.getResultsCount()
local results = gg.getResults(count)

local _x, _y = {}, {}
for i, v in ipairs(results) do
end
_x, _y = gg.getValues(_x), gg.getValues(_y)

local x, y = {}
for i, v in ipairs(results) do
if _x[i].value ~= '0' then
table.insert(x, _x[i])
end
if _y[i].value ~= '0' then
table.insert(y, _y[i])
end
end

if #x ~= #y then
return print "the results from x and y may not be the same!"
end

for loop = 1, #x do
for i, v in ipairs(x) do
x[i].value = x[loop].value
y[i].value = y[loop].value
end
gg.setValues(x)
gg.setValues(y)
gg.sleep(500)
end```

Edited by TisNquyen
##### Share on other sites

• 0
14 minutes ago, TisNquyen said:
```gg.searchNumber('', gg.TYPE_FLOAT)
gg.refineNumber('', gg.TYPE_FLOAT)
local count = gg.getResultsCount()
local results = gg.getResults(count)

local _x, _y = {}, {}
for i, v in ipairs(results) do
end
_x, _y = gg.getValues(_x), gg.getValues(_y)

local x, y = {}
for i, v in ipairs(results) do
if _x[i].value ~= '0' then
table.insert(x, _x[i])
end
if _y[i].value ~= '0' then
table.insert(y, _y[i])
end
end

if #x ~= #y then
return print "the results from x and y may not be the same!"
end

for loop = 1, #x do
for i, v in ipairs(x) do
x[i].value = x[loop].value
y[i].value = y[loop].value
end
gg.setValues(x)
gg.setValues(y)
gg.sleep(500)
end```

##### Share on other sites

• 0
44 minutes ago, XxhentaixX said:

```gg.searchNumber('', gg.TYPE_FLOAT)
gg.refineNumber('', gg.TYPE_FLOAT)
local count = gg.getResultsCount()
local results = gg.getResults(count)

local _x, _y = {}, {}
for i, v in ipairs(results) do
end
_x, _y = gg.getValues(_x), gg.getValues(_y)

local x, y = {}, {}
for i, v in ipairs(results) do
if _x[i].value ~= '0' then
table.insert(x, _x[i])
end
if _y[i].value ~= '0' then
table.insert(y, _y[i])
end
end

if #x ~= #y then
return print "the results from x and y may not be the same!"
end

for loop = 1, #x do
for i, v in ipairs(x) do
x[i].value = x[loop].value
y[i].value = y[loop].value
end
gg.setValues(x)
gg.setValues(y)
gg.sleep(500)
end```

##### Share on other sites

• 0
19 minutes ago, TisNquyen said:
```for loop = 1, #x do
for i, v in ipairs(x) do
x[i].value = x[loop].value
y[i].value = y[loop].value
end
gg.setValues(x)
gg.setValues(y)
gg.sleep(500)
end```

Main issue.
it is setting all values equal to the first results of x and y. and executing that behavior based on the amount of results.

This is the purpose of why i need the loop.
This behavior must be simplified.

1 hour ago, XxhentaixX said:

The loop has to shorten this behavior:

```for i = 1, #x do
x[i].value = x[1].value
end
gg.setValues(x)

for i = 1, #z do
z[i].value = z[1].value
end
gg.setValues(z)

for i = 1, #x do
x[i].value = x[2].value
end
gg.setValues(x)

for i = 1, #z do
z[i].value = z[2].value
end
gg.setValues(z)

for i = 1, #x do
x[i].value = x[3].value
end
gg.setValues(x)

for i = 1, #z do
z[i].value = z[3].value
end
gg.setValues(z)```

##### Share on other sites

• 0

The issue is in the code that needs to be repeated. When the code is executed for the first time, "value" fields of all sub-tables of the table ("x", for example) are set to "x[1].value", so that when the code is repeated and should set all values to second value, "x[2].value" is already modified to the value of "x[1].value", that's why each time the code is repeated, it sets all values to first value.

To actually set all values of a table to value of different table element each time, make sure that there is a copy of values that doesn't get modified and in the code that gets repeated just use values from the copy to set "value" field of sub-tables. To make copy of values, construct a table in which indexes from original table (1, 2, 3, ...) are mapped to values of "value" field of corresponding sub-tables of the original table (x[1].value, x[2].value, x[3].value, ...), for example, like this:

```local xValues = {}
for i, v in ipairs(x) do
xValues[i] = v.value
end```

Then use values of constructed table in inner loop of the code that gets repeated (slightly modified version of the loop from @TisNquyen's post above):

```for loop = 1, #x do
for i = 1, #x do
x[i].value = xValues[loop]
y[i].value = yValues[loop]
end
gg.setValues(x)
gg.setValues(y)
gg.sleep(500)
end```
##### Share on other sites

• 0

Once you set all of the values in x to the first, wouldn't the second value become the first?

Edited by TheMech

## Create an account

Register a new account

• ### Similar Content

• #### big number in arm

By blocx,

• 792 views
• #### Can't change the number.

By Nikke0123456789,

• 1,009 views
• #### Copy Number and Paste Script

By MasterC,

• 845 views
• #### install bug Bug on the number of script installations

By publ1chax,

• 2 replies
• 866 views