Jump to content
  • 0

several named value in saved list, load them to result, edit their value by the name given, clear result and send them back to saved list


Question

Posted

hello, im still new at scripting, i tried something and it works but i need simplifier scripting, heres some part of my code
 

local posX = gg.getListItems()
local posY = gg.getListItems()
local posZ = gg.getListItems()
	for i, v in ipairs(posX) do
		if v.name == 'posX' and v.flags == gg.TYPE_FLOAT then
			v.value = 100
		end
	end
	for i, v in ipairs(posZ) do
		if v.name == 'posZ' and v.flags == gg.TYPE_FLOAT then
			v.value = 1
		end
	end
	for i, v in ipairs(posY) do
		if v.name == 'posY' and v.flags == gg.TYPE_FLOAT then
			v.value = 50
		end
	end
gg.setValues(posX)
gg.setValues(posZ)
gg.setValues(posY)
gg.addListItems(posX)
gg.addListItems(posZ)
gg.addListItems(posY)

local searchResults = gg.getResults(10, nil, nil, nil, 1, 100, gg.TYPE_FLOAT)
if searchResults.name == "posX" then
	for i, v in ipairs(searchResults) do
		searchResults[i].freeze = true
		searchResults[i].name = 'posX'
	end
end
if searchResults.name == "posY" then
	for i, v in ipairs(searchResults) do
		searchResults[i].freeze = true
		searchResults[i].name = 'posY'
	end
end
if searchResults.name == "posZ" then
	for i, v in ipairs(searchResults) do
		searchResults[i].freeze = true
		searchResults[i].name = 'posZ'
	end
end
gg.addListItems(searchResults)
gg.clearResults()

do i need an arraylist / tablelist and pointer ? for my 3 float value 100;1;50 because i need to input all values more than hundreds, if i still using script code above, it will very long writing

2 answers to this question

Recommended Posts

  • 1
Posted (edited)
local searchResults = gg.getResults(10, nil, nil, nil, 1, 100, gg.TYPE_FLOAT)

would likely return nothing as you do not perform any searches beforehand.

local posX = gg.getListItems()
local posY = gg.getListItems()
local posZ = gg.getListItems()

you called it 3 times from the same list.

gg.setValues(posX)
gg.setValues(posZ)
gg.setValues(posY)
gg.addListItems(posX)
gg.addListItems(posZ)
gg.addListItems(posY)

so was the editing.

it could be as simple as this :

local saved = gg.getListItems()

for i, v in ipairs(saved) do
    if v.name == "posX" then
        v.value = 100
        v.freeze = true
    elseif v.name == "posY" then
        v.value = 50
        v.freeze = true
    elseif v.name == "posZ" then
        v.value = 1
        v.freeze = true
    end
end

gg.setValues(saved)
gg.addListItems(saved)

 

Edited by MonkeySAN
  • 0
Posted (edited)

ah so it can be like that,
what about if i need to edit them again with different value at the same time

the first, 3 values was 100;50;1
and the second, 3 values are 200;150;1
then the 3rd, 3 values 300;200;1

do i need to make an array?

local array1 = {100;50;1}
local array2 = {200;150;1}
local array3 = {300;200;1}

 

Edited by chandelier

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.