I’m using a scrollView as an inventory of purchasable items.
For each item in my data structure I call addItem() which essentially creates an image, a bit of text and a button for each item and inserts this into a display group.
I then insert this display group into the scrollView when the player clicks a button to make it visible. I need the scrollView to house different categories of items, so I’m trying to remove the elements as needed but running into an error every time:
?:0: attempt to index field ‘parent’ (a nil value)
message
stack traceback:
?: in function <?:218>
[C]: ?
?: in function <?:459>
?: in function <?:218>
The code I’m using to remove the elements from the scrollView is:
[lua]
for i = self.struct[“itemScrollView”].numChildren,1,-1 do
local child = self.struct[“itemScrollView”][i]
child:removeSelf()
child = nil
--self.struct[“itemScrollView”]:remove(child)
--self.struct[“itemScrollView”][i]:removeSelf()
end
[/lua]
This runs through as expected (three times as I have 3 different items), however after running through this and ultimately coming to the next tick of my gameloop I’m presented with the aforementioned error.
As you can see from the commented lines I’ve tried numerous different approaches, but each causes the same error.
Any help would be appreciated.