Python Reference:  Blender 3D Game Engine



 


Tuples

Creating a Tuple

A tuple is a data structure that can't be changed after it is created.  New data can't be added to it.  Data can't be deleted from it.

It is enclosed with parentheses and items are separated by commas.  A tuple can hold numbers, objects, strings, other lists, etc

Example:


# create a tuple of float numbers
numberList = ( 1.0, 2.0, 1.0, 3,0, 9.0, 2.0)

# create a tuple of strings.
groceryList = ("pizza", "milk", "chips", "tacos", "chicken wings")

Retrieving items from a tuple:

The 1st position in a tuple is 0, 2nd position is 1, 3rd position is  2, etc

Example:


# create a tuple
groceryList = ( "pizza", "milk", "chips", "tacos", "chicken wings")

# Retrieve 1st item from tuple
x = groceryList[0]

# Retrieve 3rd item from tuple
y = groceryList[2]

# print the first and third items in the tuple
print(x, y)

########   it will print

"pizza", "chips"

########

Example:

# create a tuple of float lists
worldOrientation = ([ 1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0])

# Retrieve the 2nd list in the tuple
a =  worldOrientation[1]

# Retrieve the 1st item in the 1st list in the tuple
b =  worldOrientation[0][0]

# print a
print(a)

# print b
print(b)

##########   it will print

[0.0, 1.0, 0.0]
1.0

##########
   





The Blender 3D and Blender 3D game engine tutorials were created as a series of step by step instructions to help you create computer games. Casual video games, First Person Shooter, role playing games, racing simulations and more. Use the Blender 3D tutorials to model and program your own three-dimensional world and then play on your computer.