🔥 Lifetime deal! Get Control Surface Studio for Just £67 👉 Click Here To Get It
Time left... mailtimers.com
⚠️ Lifetime licenses are ending soon, get yours before they're gone ⚠️
Your shopping cart is empty.

Custom lists index bug?

Submitted by HDV on Thu, 04/06/2023 - 12:46
HDV
Control Surface Studio User

By definition Python lists starts at index 0.

Please look at the following "reaction":

Listener: script is initialised
Action:
self.clear_list("list2")
self.add_to_list("list2", "A1", 1)
self.add_to_list("list2", "B2", 2)
self.add_to_list("list2", "C3", 3)
a = self.get_list_item("list2",1)
b = self.get_list_item("list2",2)
c = self.get_list_item("list2",3)
self.log_message("1: " + str(a) + " - 2: " + str(b) + " - 3: " + str(c))
self.clear_list("list2")
self.add_to_list("list2", "A0", 0)
self.add_to_list("list2", "B1", 1)
self.add_to_list("list2", "C2", 2)
a = self.get_list_item("list2",0)
b = self.get_list_item("list2",1)
c = self.get_list_item("list2",2)
self.log_message("0: " + str(a) + " - 1: " + str(b) + " - 2: " + str(c))

In the "log.txt" file the messages are
RemoteScriptMessage: (css_test) 1: A1 - 2: B2 - 3: C3
RemoteScriptMessage: (css_test) 0: C3 - 1: A0 - 2: B1

The second message is strange, shouldn´t it be 0: A0 - 2: B1 - 3: C2 ???

Dieter

Topic Category: 

1 Responses

Comments

HDV
Control Surface Studio User
#1

Let´s have a look at the definition of the "get_list_item" function.

def get_list_item(self, list_name, item_num):
try:
theList = self.get_list(list_name)
if theList is False:
return False
list_len = self.get_list_length(list_name)
if list_len is False:
return
if list_len >= item_num:
return theList[item_num - 1]
else:
self.log_message('csslog: Custom list "' + str(list_name) + '" does not have ' + str(item_num) + ' items')
return False
except Exception as e:
self.log_message('csslog: There was an error in "get_list_item"', str(e))
return False

"return theList[item_num - 1]" explains everything: if I set item_num=0 it returns element with index -1 and this is by python syntax the last element in the list.
May be the fault is in the CSS user interface? When in a condition "script - custom list - list item" is selected and input for the number is 1 then self.get_list_item("list1", 0) is generated!

Dieter

upload files: