Python List: append

append(val)
  • Adds an item to a BGE python list.

val:

  • value to be added to the python list.
  • Type:  Boolean or string or integer or etc.
Sample Code: Part 1

################## create an empty list

# import bge
import bge

# get the current controller
cont = bge.logic.getCurrentController()

# get the object the controller is attached to
obj = cont.owner

# create an empty list
# I named it lap_times

obj["lap_times"] = []

Sample Code: Part 2

################## add a value to the list  

# import bge
import bge

# get the current controller
cont = bge.logic.getCurrentController()

# get the object the controller is attached to
obj = cont.owner

# obj["lap_times"] is a python list I created in Sample Code Part 1
# I attached the python list to the game object


# add new lap time of 215 seconds to list
obj["lap_times"].append(215)