Jump to content
  • 0

Help me with loop in script


dgmon
 Share

Question

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

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

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

Link to comment
Share on other sites

  • 0
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?

Link to comment
Share on other sites

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

  • 0
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

 

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.