Jump to content
  • 0

Question

Posted
function SPM()
for i = 1,20 do
    gg.setVisible(false)
    local t = gg.getListItems()
    for i, v in ipairs(t) do
        if v.name == 'R' then
            v.value = "-2.0"
        gg.setValues(t)
        gg.addListItems(t)
        end
    end
    end
    end

Hello, sorry for my inconvenience problem.

I want the saved list item with name "R" modified repeatedly up to 20 times.

Please help me with the scripting. I hope my question would be answered.

 

 @CmP @MonkeySAN @blocx

5 answers to this question

Recommended Posts

  • 0
Posted
local savedValues = gg.getListItems() -- Enough to get items once if list won't change during execution of loop
local targetValues = {}
for i, v in ipairs(savedValues) do
  if v.name == "R" then
    targetValues[#targetValues + 1] = {
      address = v.address,
      flags = v.flags,
      value = "-2.0"
    }
  end
end
for i = 1, 20 do
  gg.setValues(targetValues) -- doesn't really make sense without delay
end

And, please, don't mention anyone in questions that are not directed to someone specifically.

  • 0
Posted
9 hours ago, CmP said:
 

Thank you for your help CmP. I've tried and it seem like not working. Is there any wrong, i just literally copy pasted. Sorry for my inconvenience and lack of knowledge.

  • 0
Posted
10 hours ago, dgmon said:

not working

The question is what you define as working. You asked for the code that modifies value(s) from saved list that are named "R" to "-2.0" 20 times in loop. The code above should do exactly that. Maybe that's not exactly what you need?

  • 0
Posted
On 11/1/2024 at 6:27 PM, CmP said:
local savedValues = gg.getListItems() -- Enough to get items once if list won't change during execution of loop
local targetValues = {}
for i, v in ipairs(savedValues) do
  if v.name == "R" then
    targetValues[#targetValues + 1] = {
      address = v.address,
      flags = v.flags,
      value = "-2.0"
    }
  end
end
for i = 1, 20 do
  gg.setValues(targetValues) -- doesn't really make sense without delay
end

And, please, don't mention anyone in questions that are not directed to someone specifically.

Should be sleeping in between each edit else it wont work as expected
 

for i=1, 20 do
    gg.setValue(targetValue)
    gg.sleep(100)
end 
  • 0
Posted
37 minutes ago, MAARS said:

Should be sleeping in between each edit else it wont work as expected

On 11/1/2024 at 7:27 PM, CmP said:
for i = 1, 20 do
  gg.setValues(targetValues) -- doesn't really make sense without delay
end
Quote

-- doesn't really make sense without delay

 

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.