Jump to content
  • 0

increment index number


Platonic
 Share

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()
gg.loadResults(a)
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
Link to comment
Share on other sites

Recommended Posts

  • 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
  local resultAddress = results[i].address + 0x44
  for j = 1, 50 do
    x[#x + 1] = {address = resultAddress, flags = gg.TYPE_FLOAT}
    end
end

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

local z = {}
for i = 1, count, 1 do
  local resultAddress = results[i].address + 0x4C
  for j = 1, 50 do
    z[#z + 1] = {address = resultAddress, flags = gg.TYPE_FLOAT}
    end
end

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

a = gg.getListItems()
gg.loadResults(a)
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
Link to comment
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
  xChecker[i] = {address=v.address+0x44, flags=gg.TYPE_FLOAT}
  yChecker[i] = {address=v.address+0x4c, flags=gg.TYPE_FLOAT}
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.

Link to comment
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
  _x[i] = {address = v.address + 0x44, flags = gg.TYPE_FLOAT}
  _z[i] = {address = v.address + 0x4C, flags = gg.TYPE_FLOAT}
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
Link to comment
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
  _x[i] = {address = v.address + 0x44, flags = gg.TYPE_FLOAT}
  _z[i] = {address = v.address + 0x4C, flags = gg.TYPE_FLOAT}
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

 

 

Screenshot_2022-02-12-16-28-49-865_com.pixonic.wwr.jpg

Link to comment
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
Link to comment
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
  _x[i] = {address = v.address + 0x44, flags = gg.TYPE_FLOAT}
  _y[i] = {address = v.address + 0x4C, flags = gg.TYPE_FLOAT}
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
Link to comment
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
  _x[i] = {address = v.address + 0x44, flags = gg.TYPE_FLOAT}
  _y[i] = {address = v.address + 0x4C, flags = gg.TYPE_FLOAT}
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

 

 

Screenshot_2022-02-12-16-55-05-668_com.pixonic.wwr.jpg

Link to comment
Share on other sites

  • 0
44 minutes ago, XxhentaixX said:

 

Screenshot_2022-02-12-16-55-05-668_com.pixonic.wwr.jpg

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
  _x[i] = {address = v.address + 0x44, flags = gg.TYPE_FLOAT}
  _y[i] = {address = v.address + 0x4C, flags = gg.TYPE_FLOAT}
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

 

Link to comment
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)

 

 

Link to comment
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
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.