List Function Questions
Fyrdraca
25 Dec 2015, 05:35I've been beating the bush up and down, trying to get find the right function for this - I'm sure it exists, it has to, it's too basic not to - but what function is used to return the number of values in a list?
Also, what function clears all values from a list?
I know these are basic questions, but I'm still getting my sea legs.
Also, what function clears all values from a list?
I know these are basic questions, but I'm still getting my sea legs.
HegemonKhan
25 Dec 2015, 06:50quantity of items in a list~dictionary:
http://docs.textadventures.co.uk/quest/ ... count.html
http://docs.textadventures.co.uk/quest/ ... count.html
remember that the indexing starts at zero however, which means that the index of the last item in your list is: ListCount (list) - 1
ListCount (list), (with NO minus 1), is 'out of bounds' ERROR, if used for the index value
for example:
pretend that we have a list with 5 items in it
index (memory location~address, used to get the data~value at that index, that memory~location~address): blah items
0: item_1 (first item out of 5 items in the list)
1: item_2 (second item out of 5 items in the list)
2: item_3 (third item out of 5 items in the list)
3: item_4 (fourth item out of 5 items in the list)
4: item_5 (fifth and last item out of 5 items in the list)
----
5: (no sixth item exists, 'out of bounds' ERROR)
-----------------------
to Clear all items, you got to individually remove each item (use a 'foreach' loop to do so, especially if your list has lots of items, lol)
otherwise, we'd be dealing with programming technicalities: how quest handles memory leaks in terms of trying to over-write your list~dictionary 's name, using the 'NewList'~'NewDictionary', and how to delete that now unused data (so it's not just floating around unusable~unreclaimable) which is a memory leak.
----------------------
P.S.
here's a link to a guide I made on using lists~dictionaries:
viewtopic.php?f=18&t=5137
and here's some more fancy usage lists and dictionaries, which will help you (if you can understand it ~ as it's poor code - as it was back when I was learning how to use lists and dictionaries myself, lol), if you want to take a look at it:
viewtopic.php?f=18&t=5138
ask if you got any questions or need help with anything!
http://docs.textadventures.co.uk/quest/ ... count.html
http://docs.textadventures.co.uk/quest/ ... count.html
remember that the indexing starts at zero however, which means that the index of the last item in your list is: ListCount (list) - 1
ListCount (list), (with NO minus 1), is 'out of bounds' ERROR, if used for the index value
for example:
pretend that we have a list with 5 items in it
index (memory location~address, used to get the data~value at that index, that memory~location~address): blah items
0: item_1 (first item out of 5 items in the list)
1: item_2 (second item out of 5 items in the list)
2: item_3 (third item out of 5 items in the list)
3: item_4 (fourth item out of 5 items in the list)
4: item_5 (fifth and last item out of 5 items in the list)
----
5: (no sixth item exists, 'out of bounds' ERROR)
-----------------------
to Clear all items, you got to individually remove each item (use a 'foreach' loop to do so, especially if your list has lots of items, lol)
otherwise, we'd be dealing with programming technicalities: how quest handles memory leaks in terms of trying to over-write your list~dictionary 's name, using the 'NewList'~'NewDictionary', and how to delete that now unused data (so it's not just floating around unusable~unreclaimable) which is a memory leak.
----------------------
P.S.
here's a link to a guide I made on using lists~dictionaries:
viewtopic.php?f=18&t=5137
and here's some more fancy usage lists and dictionaries, which will help you (if you can understand it ~ as it's poor code - as it was back when I was learning how to use lists and dictionaries myself, lol), if you want to take a look at it:
viewtopic.php?f=18&t=5138
ask if you got any questions or need help with anything!

jaynabonne
26 Dec 2015, 11:12To clear all values from a list, just make a new list.
HK, you will not have memory leaks in Quest (as you don't in Java, C#, JavaScript, etc either) as values are garbage collected automatically when they're no longer used. You do not need to remove all the items from the list. Creating a new list and assigning it to the old list variable or attribute will make all the previous values no longer referenced (assuming they're not referenced somewhere else), and they will just go away.
HK, you will not have memory leaks in Quest (as you don't in Java, C#, JavaScript, etc either) as values are garbage collected automatically when they're no longer used. You do not need to remove all the items from the list. Creating a new list and assigning it to the old list variable or attribute will make all the previous values no longer referenced (assuming they're not referenced somewhere else), and they will just go away.