Jump to content
  • 0

addListItems with v.name


Question

Posted

I am trying to addListItems items with name like below but when use getList item getting error

 

 

gg.setVisible(false)

gg.searchNumber("500", gg.TYPE_DWORD)

local t = gg.getResults(500)

for i, v in ipairs(t) do

v.name = "Characters"

v.freeze = false

end

gg.addListItems(t)

gg.toast("Done")

gg.clearResults()

 

 

--Getting Error to get getListitems with "v.name characters

local ros = gg.getListItems()

for i, v in ipairs(ros) do

if v.name == "Characters" then

local x = gg.getListItems()

gg.loadResults(t)

end

end

 

 

 

Sent from my HD1901 using Tapatalk

 

 

10 answers to this question

Recommended Posts

  • 0
Posted

like this..?

local ros = gg.getListItems()

for i, v in ipairs(ros) do
  if v.name ~= "name" then
    ros[i] = nil
  end
end
gg.loadResults(ros)
gg.toast("Done")

 

  • 0
Posted (edited)

In the first half of the code instead of

v.name = "Characters"

do

t[i].name = "Characters"

 

you are only setting the name of v.name while in the loop which makes no change to t which you then add to list

it cant find the name because there are no items in the list with the name

Edited by BadCase
  • 0
Posted (edited)
1 hour ago, BadCase said:

you are only setting the name of v.name while in the loop which makes no change to t

This is wrong. "t" is a table of tables, so "v" in our loop refers to particular sub-table (one per iteration). Lua reference manual states the following: 

Quote

Tables, functions, threads, and (full) userdata values are objects: variables do not actually contain these values, only references to them. Assignment, parameter passing, and function returns always manipulate references to such values; these operations do not imply any kind of copy.

In our case it means that "v" is a reference to same table as "t[index]", so any of these references can be used to set value of a field in that same table. Here is the code to illustrates that "name" field of sub-tables is indeed being set: 

local t = {
  {address = 0x11223344, flags = gg.TYPE_DWORD, value = 0},
  {address = 0x11223348, flags = gg.TYPE_DWORD, value = 0}
}
for i, v in ipairs(t) do
  v.name = "Characters"
end
for i, v in ipairs(t) do
  print(i, t[i].name)
end
Edited by CmP
Replaced "t[i]" with "t[index]" because "[i]" unintentionally applies Italic modifier to subsequent text.
  • 0
Posted (edited)

Hmm I thought I had experienced something similar which I fixed by doing that but I guess not

 

EDIT I think it was an error in my old modded thing that shall not be mentioned here

Edited by BadCase
  • 0
Posted (edited)
30 minutes ago, BadCase said:

Hmm I thought I had experienced something similar which I fixed by doing that but I guess not

Could be the case when elements of traversed table need to be modified themselves. Assigning new value to "v" has no effect on "t[index]", so referring to table element explicitly is required in this case. Example: 

-- Wrong, table is unchanged
for i, v in ipairs(t) do
  v = {address = 0x10203040 + 4 * i, flags = gg.TYPE_DWORD, value = "0"}
end

-- Correct
for i, v in ipairs(t) do
  t[i] = {address = 0x10203040 + 4 * i, flags = gg.TYPE_DWORD, value = "0"}
end
Edited by CmP
  • 0
Posted
like this..?
local ros = gg.getListItems()for i, v in ipairs(ros) do if v.name ~= "name" then   ros[i] = nil endendgg.loadResults(ros)gg.toast("Done")

 

This is working like charm [emoji4]

Sent from my HD1901 using Tapatalk

  • 0
Posted
This is working like charm [emoji4]

Sent from my HD1901 using Tapatalk

One more request is

How to revert all editied values in gg script
If I edited 100 values like

109 to 106

I want revet it back original 109 what code should I use

if revert ~= nil then gg.setValues(revert) end?

But above not working [emoji17]

Sent from my HD1901 using Tapatalk

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
×
×
  • 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.