kkbs4u Posted July 20, 2021 Posted July 20, 2021 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) dov.name = "Characters"v.freeze = falseendgg.addListItems(t)gg.toast("Done")gg.clearResults() --Getting Error to get getListitems with "v.name characterslocal ros = gg.getListItems()for i, v in ipairs(ros) doif v.name == "Characters" thenlocal x = gg.getListItems()gg.loadResults(t)endend Sent from my HD1901 using Tapatalk
0 HEROGAMEOfficial Posted July 20, 2021 Posted July 20, 2021 Learn API gg: https://gameguardian.net/help/classgg.html
0 CmP Posted July 20, 2021 Posted July 20, 2021 You need to either filter the table returned by "getListItems" function via "deleting" (setting to nil) elements that have different name or build a new table only with elements that have desired name. Here is an example of implementing the first approach (first 5 lines of the code): How to remove named value in the save list? (#86ip1n3c)
0 MonkeySAN Posted July 20, 2021 Posted July 20, 2021 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") 3
0 BadCase Posted July 20, 2021 Posted July 20, 2021 (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 July 20, 2021 by BadCase 1
0 CmP Posted July 20, 2021 Posted July 20, 2021 (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 July 20, 2021 by CmP Replaced "t[i]" with "t[index]" because "[i]" unintentionally applies Italic modifier to subsequent text.
0 BadCase Posted July 20, 2021 Posted July 20, 2021 (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 July 20, 2021 by BadCase
0 CmP Posted July 20, 2021 Posted July 20, 2021 (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 July 20, 2021 by CmP 1
0 kkbs4u Posted July 21, 2021 Author Posted July 21, 2021 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 kkbs4u Posted July 21, 2021 Author Posted July 21, 2021 This is working like charm [emoji4]Sent from my HD1901 using TapatalkOne 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
Question
kkbs4u
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
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 accountSign in
Already have an account? Sign in here.
Sign In Now