ArrayLists

How can i create an arrary list that hold only 50 values? A task will be passing new values into this arraylist every frame but i want the new value to enter with the oldest one being removed. I’ve tried to get it working with

Doesnt seem to like that however. Is there a better way to do this as I cant find arrays in the manual and the python library hasnt seem much help either. Many thanks

something like that



self.table.append( "yourstuff")
if len(self.table)>50:
    self.table.pop(0)

the oldest entry will be at place 0, the newest one at place 49.
if you need to access the newest one just do self.table[-1]

Many thanks got that working finally. Ran into a bit of a problem calculating the difference betweem two array indexes but discovered that it was because there is only a tiny, if not any, difference between values when your adding a new index for each run of a task (as task runs many time a sec). Had to extend the amount of time between each append…if anyones interested:

self.gladControl.setR(mpos.getY() * 200)
        self.gladTrajectory = (self.gladControl.getR() * -0.2) - 30
        if self.prevTime == 24:
            self.table.append(self.gladTrajectory)
            #print 'loaded one'
            if len(self.table) > 51: 
                self.table.pop(0)
                #print 'pop one'  
            self.prevTime = 0
        if self.prevTime <= 23:
            self.prevTime = self.prevTime + 1
        return Task.cont
[quote]
Thanks again 
[/quote]