CreateList Modifying Items.

Discuss any general programming issues here
Post Reply
Bugala
Posts: 1395
Joined: Sun Feb 14, 2010 7:11 pm

CreateList Modifying Items.

Post by Bugala »

It says in the CreateList description:

"The disadvantage is that adding or removing items may only be done via InsertItem() and RemoveItem(). You must not add or remove items from optimized lists by modifying the table directly. It's necessary to use the functions mentioned above. "

But is this considered modifying the list (Referring to line Temp[40][1].a = 5):

Code: Select all

temp = CreateList()

For n=0 To 100
	InsertItem(Temp, {[0] = { a=n },
			  [1] = { a=n+2 }
			  }, n)
Next

Temp[40][1].a = 5
DebugPrint(Temp[40][1].a)
or is it only when I concretely remove an item from the list it is considered modifying the list?

Also, can the CreateList then contain any kind of Items, as in could I mix Functions, Numbers, Strings, or Subtables with different configurations, like:

Code: Select all

Function MyPrint()
   Debugprint("Hello World")
EndFunction

Temp = CreateList()
Table1 = { [0] = {a=1},
                         [1] = {b=2},
                         c = 3}
Table2 = { [2] = {a=4},
               b = 5}
Func = MyPrint
InsertItem(Temp, Table1)
InsertItem(Temp, Table2)
InsertItem(Temp, Func)
InsertItem(Temp, "string")
InsertItem(Temp, 10)
For at least when doing this, it doesnt crash. But do I lose the speed benefit or something, doing this way?
Flinx
Posts: 347
Joined: Sun Feb 14, 2021 9:54 am
Location: Germany

Re: CreateList Modifying Items.

Post by Flinx »

I think the key point is that Temp is a list with integer indexes, which can be seen in

Code: Select all

ForEach(Temp, DebugPrint)
What the list contains as elements should not matter.
User avatar
airsoftsoftwair
Posts: 5848
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: CreateList Modifying Items.

Post by airsoftsoftwair »

Bugala wrote: Fri Dec 12, 2025 5:09 pm But is this considered modifying the list (Referring to line Temp[40][1].a = 5):
No, the doc clearly says that the only modification that is forbidden is adding or removing items without using functions from the table library. Just modifying the values of existing items is perfectly allowed. The only thing that's not allowed with optimized lists is adding or removing items manually without using table library functions.
Post Reply