Clear all values of list variable


#1

Quick and kinda noob question here.

How can I completely clear a list variable so there’s nothing left stored?

I have a set variable command looping where the end of loop is varying from run to run (will sometime set values for 0 to 15, and some other time 0 to 11.) I don’t want values stored in position 12 to 15 to stick when they don’t get overridden.

Thanks,


#2

@ady624 you mate sure have a trick up your sleeve?


#3

I have not seen a way to remove keys, one approach I’ve used is to manually maintain a length property on the list (could also be a top-level variable to if your piston only has one array to maintain.

  • To push an item assign the value to myArray at index int(myArray[length]) then assign the value int(myArray[length]) + 1 to myArray at index length
  • To iterate use a for loop from zero to int(myArray[length]) - 1 (be sure to use an integer variable rather than $index which does not work with zero)
  • To reset the array set myArray at index length to 0

#4

Thanks, I’ll try this tomorrow and report back.

Do you think this should be added to low priority feature suggestion, in the form of a new command in location? Since I’m not very used to coding I always have a hard time to judge whether I’m erring or not.