In the attached file I have a Python script that is designed to change the worlds background color, ambient color, the mass an object (since I can’t find a way to change the gravity for a single object, rather then the entire scene), and the energy of a sun lamp. The script creates a list of custom (programing) objects, each with their own variables, then checks the z location of the rocket by iterating through the list, and then assigns the values (bg color, mass, ect) based on the rockets z location. The trouble is that none of the changes are applied, despite the console telling me that the conditions for them are triggered (it prints “True”).
# import bge moduleimport bge
class WorldObjData:
def __init__(self, heigth, color, brightness, gravity):
self.heigth = heigth
self.ambColor = color
self.color = [color[0], color[1], color[2], 1]
self.brightness = brightness
self.gravity = gravity
# get the render module
rend = bge.render
cont = bge.logic.getCurrentController()
own = cont.owner
scene = bge.logic.getCurrentScene()
sun = scene.objects["Sun"]
BU0 = WorldObjData(0.0, [0.2, 0.458, 1], 1, 1)
BU100 = WorldObjData(10.0, [0, 0.322, 1], 0.99, 0.85)
BU200 = WorldObjData(20.0, [0, 0.257, 0.8], 0.98, 0.70)
BU300 = WorldObjData(30.0, [0, 0.193, 0.6], 0.97, 0.55)
BU400 = WorldObjData(70.0, [0, 0.129, 0.4], 0.96, 0.40)
BU500 = WorldObjData(50.0, [0, 0.064, 0.2], 0.95, 0.35)
BU600 = WorldObjData(60.0, [0, 0, 0], 0.94, 0.2)
worldPos = own.worldPosition[2]
own["worPos"] = own.worldPosition[2] # debugging
getHeight = [BU600, BU500, BU400, BU300, BU200, BU100, BU0]
for key in getHeight:
if worldPos >= key.heigth:
print("True") #console debugging
rend.setAmbientColor(key.ambColor)
own["bgColor"] = key.ambColor[1]
rend.setBackgroundColor(key.color)
sun.energy = key.brightness
own.mass = key.gravity
own["sun"] = sun.energy # debugging
own["massR"] = own.mass # debugging
Any ideas on what I’m doing wrong?
Attachments
rocketSim.blend (536 KB)