Jump to content
  • 0

saving values ​​to a list and changing certain ones


BotBot72826

Question

help me please

 

 I ran into a problem

 

 I need to save a few unrelated values and then go back and change a specific one

 Can you show an example of a script where this is implemented

 

is it possible to rename saved values and then search for them by name in the save list?

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

On 1/15/2023 at 11:10 AM, BotBot72826 said:

help me please

 

 I ran into a problem

 

 I need to save a few unrelated values and then go back and change a specific one

 Can you show an example of a script where this is implemented

 

is it possible to rename saved values and then search for them by name in the save list?

you can, but how do you plan to detect a specific number?

Link to comment
Share on other sites

when u save the value into a table they have index and values to specify the values use index 
assume u save the results in : my_Tab and u want to change the adresses which have the values of 123 to 321 use for loop and condition and another table which will contain ur values(let's name it newTab): 
for index,v in ipairs(my_Tab) do 
if my_Tab[index].value == 123 then
--- condition body (filter the unwanted values)
newTab[#newTab+1].address= my_Tab[index].address
---change to the value u want
newTab[#newTab].value = 123
end
-----
end
gg.setValues(newTab)
newTab = gg.getValues(newTab)

note : and if u want to change 123 and 456 and 789 to 999 use this condition : 
if my_Tab[index].value == 123 or my_Tab[index].value == 456 or my_Tab[index].value == 789 then
-- condition body 
end

Link to comment
Share on other sites

On 1/15/2023 at 9:10 AM, BotBot72826 said:

is it possible to rename saved values and then search for them by name in the save list?

Yes by changing the index name 
when u add the results to a table the indexs are from 1 to the lengh of the result similar to the answer above 
u can rename the index by using some methods like : 

myTable['renamed'].value = myTable[2].value ---> we add new index named : changed and make the value of it the one we want to change it's name
myTable[2] = nil -----> we remove the old index from the table
 

Link to comment
Share on other sites

Hi @BotBot72826, you can make the result of a function as variable. This will saved in memory that you can access them later, make sure to check if the function returns list or dictionary. I usually use switches to control values over any function and make it global variable instead of local.

switch = {
	[1] = 'this is first',
	speed_hack = 500,
	functional = function() print("ano") end,
}

-- Print default value of switch
print(switch[1])
print(switch['speed_hack'])
switch['functional']()

-- Change switch value
switch[1] = 'knx'
switch['speed_hack'] = 400
switch['functional'] = function() print('Changed') end

-- Print changed value of switch
print(switch[1])
print(switch['speed_hack'])
switch['functional']()

-- Check switch value or condition.
if switch[1] == 'knx' then
	print('True: Its knx')
else
	print('False: not knx')
end
if switch['speed_hack'] == 200 then
	print('True: Its 200')
else
	print('False: not 200')
end
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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