Jump to content
  • 1

How to remove unwanted list items from list


Question

Posted (edited)
  gg.addListItems(gg.getResults(gg.getResultsCount()))
  res = gg.getListItems()
  gg.clearResults()
  if not false then gg.removeListItems(res) end
  for i, v in ipairs(res) do
    v.address = v.address + 0x8
  end
  gg.addListItems(res)
  res = gg.getListItems()
  if not false then gg.removeListItems(res) end
  for i, v in ipairs(res) do
    if v.value == 12340000 then
      v.name = "Name 2"
     elseif v.value == 12345000 then
      v.name = "Name 2"
     elseif v.value == 12345600 then
      v.name = "Name 3"
     else 
      -- remove the rest of the list
    end
  end
  gg.addListItems(res)
  ress = gg.getListItems()
  if not false then gg.removeListItems(res) end
  for i, v in ipairs(res) do
    v.address = v.address - 0x8
  end
  gg.addListItems(res)

 

Edited by Ardit19

2 answers to this question

Recommended Posts

  • 0
Posted (edited)

Hi @Ardit19,

if not false then gg.removeListItems(res) end

I'm not sure what you're trying to do here. Are you checking if results are empty or you're doing some flagging here?

--Check if results are empty:
checks = gg.getResultsCount()
if checks ~= nil then
	res = gg.getResults(checks)
	gg.clearResults()
	for i, v in ipairs(res) do
		v.address = v.address + 0x8
	end
	gg.addListItems(res)
end

If you're doing some flagging/conditioning, you need to store it as variable so you can edit it anywhere.

flags = false
if not flags then
	gg.removeListItems(res)
end

/*******************************************\

gg.addListItems(gg.getResults(gg.getResultsCount()))
  res = gg.getListItems()
  gg.clearResults()
  if not false then gg.removeListItems(res) end
  for i, v in ipairs(res) do
    v.address = v.address + 0x8
  end
  gg.addListItems(res)

It is better that you're editing the 'res' variable first before adding them to saved list using addListItems(). Otherwise, you will have duplicated items in your saved list.
/*******************************************\

Quote

How to remove unwanted list items from list

Coming to your question. You can store them first into a temporary variable:

temp_res = {}

for i, v in ipairs(res) do
	if v.value == 12340000 then
		temp_res[#temp_res + 1] = {
			name = "Name 2"
			address = v.address
			value = v.value
			flags = v.flags
		}
	elseif v.value == 12345000 then
		temp_res[#temp_res + 1] = {
			name = "Name 3"
			address = v.address
			value = v.value
			flags = v.flags
		}
	elseif v.value == 12345600 then
		temp_res[#temp_res + 1] = {
			name = "Name 4"
			address = v.address
			value = v.value
			flags = v.flags
		}
	end
end

gg.addListItems(temp_res)

Or you can edit remove it directly, the index will change:

for i, v in ipairs(res) do
	if v.value == 12340000 then
		v.name = "Name 2"
	elseif v.value == 12345000 then
		v.name = "Name 3"
	elseif v.value == 12345600 then
		v.name = "Name 4"
	else
		table.remove(res, i)
	end
end

gg.addListItems(res)

Edit directly without changing indexes:

for i, v in ipairs(res) do
	if v.value == 12340000 then
		v.name = "Name 2"
	elseif v.value == 12345000 then
		v.name = "Name 3"
	elseif v.value == 12345600 then
		v.name = "Name 4"
	else
		res[i] = nil
	end
end

gg.addListItems(res)

/*******************************************\

Edited by MC874
changing 0 to nil.
  • 0
Posted
1 hour ago, MC874 said:

Hi @Ardit19,

if not false then gg.removeListItems(res) end

I'm not sure what you're trying to do here. Are you checking if results are empty or you're doing some flagging here?

--Check if results are empty:
checks = gg.getResultsCount()
if checks ~= 0 then
	res = gg.getResults(checks)
	gg.clearResults()
	for i, v in ipairs(res) do
		v.address = v.address + 0x8
	end
	gg.addListItems(res)
end

If you're doing some flagging/conditioning, you need to store it as variable so you can edit it anywhere.

flags = false
if not flags then
	gg.removeListItems(res)
end

/*******************************************\

gg.addListItems(gg.getResults(gg.getResultsCount()))
  res = gg.getListItems()
  gg.clearResults()
  if not false then gg.removeListItems(res) end
  for i, v in ipairs(res) do
    v.address = v.address + 0x8
  end
  gg.addListItems(res)

It is better that you're editing the 'res' variable first before adding them to saved list using addListItems(). You will have duplicated items in your saved list.
/*******************************************\

Coming to your question. You can store them first into a temporary variable:

temp_res = {}

for i, v in ipairs(res) do
	if v.value == 12340000 then
		temp_res[#temp_res + 1] = {
			name = "Name 2"
			address = v.address
			value = v.value
			flags = v.flags
		}
	elseif v.value == 12345000 then
		temp_res[#temp_res + 1] = {
			name = "Name 3"
			address = v.address
			value = v.value
			flags = v.flags
		}
	elseif v.value == 12345600 then
		temp_res[#temp_res + 1] = {
			name = "Name 4"
			address = v.address
			value = v.value
			flags = v.flags
		}
	end
end

gg.addListItems(temp_res)

Or you can edit remove it directly, the index will change:

for i, v in ipairs(res) do
	if v.value == 12340000 then
		v.name = "Name 2"
	elseif v.value == 12345000 then
		v.name = "Name 3"
	elseif v.value == 12345600 then
		v.name = "Name 4"
	else
		table.remove(res, i)
	end
end

gg.addListItems(res)

Edit directly without changing indexes:

for i, v in ipairs(res) do
	if v.value == 12340000 then
		v.name = "Name 2"
	elseif v.value == 12345000 then
		v.name = "Name 3"
	elseif v.value == 12345600 then
		v.name = "Name 4"
	else
		res[i] = nil
	end
end

gg.addListItems(res)

/*******************************************\

Second solution does not work as I tried multiple times, I got it from chatGPT. As per the rest solutions will try. Thanks for the answer!

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.