I’m having problems adding an object to another scene (inventory hud scene).
main scene where the game is running = Scene
inventory overlay scene = inventory
object to be added = log (on the second layer of “Scene”)
empty object in scene “inventory” = slot1
In the main character script in “Scene” I have tried the following code:
hud = logic.getSceneList["inventory"]
hud.addObject['log','slot1']
But the code doesn’t work.
This is the complete code on the player:
import bge
cont = bge.logic.getCurrentController()
scene = bge.logic.getCurrentScene()
own = cont.owner
hud = logic.getSceneList["inventory"]
move = cont.actuators['move'] # set motion actuator variable
pressup = cont.sensors['up'] # set Keyboard up variable
pressdown = cont.sensors['down'] # set Keyboard down variable
pressleft = cont.sensors['left'] # set Keyboard left variable
pressright = cont.sensors['right'] # set Keyboard right variable
jump = cont.sensors['jump'] # set Keyboard space variable
speed = move.dLoc[1] # set motion variable
rotation = move.dRot[2] # set rotation variable
hitGround = cont.sensors['hitGround']
treeHit = cont.sensors['treeDetect']
logHit = cont.sensors['loghit']
logObj = logHit.hitObject
hitObj = treeHit.hitObject
lmb = cont.sensors['lmb']
use = cont.sensors['use']
forcer = [ 0.0, 200.0, 0.0]
forcel = [ 0.0, -200.0, 0.0]
local = True
player = scene.objects['player']
if pressup.positive: # Move forward
speed = 0.2
move.dLoc = [0.0,speed,0.0]
cont.activate(move)
elif pressdown.positive: # Move down
speed = -0.2
move.dLoc = [0.0,speed,0.0]
cont.activate(move)
else: # stop moving
speed = 0
move.dLoc = [0.0, speed, 0.0]
if pressleft.positive: # rotate left
rotation = +0.05
move.dRot = [0.0, 0.0 , rotation]
cont.activate(move)
elif pressright.positive: # rotate right
rotation = -0.05
move.dRot = [0.0, 0.0 , rotation]
cont.activate(move)
else: # stop rotating
rotation = 0
move.dRot = [0.0, 0.0, rotation]
if jump.positive and not own['jumping']: # jump
own.applyForce([0,0,2000],True)
own['jumping'] = True
if hitGround.positive: # jump
own['jumping'] = False
# delete trees if lower then 1 hitcount
if lmb.positive and treeHit:
hitObj['hitcount'] -= 1
if hitObj['hitcount'] == 0:
addlog = scene.addObject('log','itemDropper')
addlog1 = scene.addObject('log','itemDropper')
addlog2 = scene.addObject('log','itemDropper')
addlog.worldPosition = treeHit.hitPosition
addlog1.worldPosition = treeHit.hitPosition
addlog2.worldPosition = treeHit.hitPosition
a,b,c = addlog1.localPosition
addlog1.localPosition = [a,b,c+10]
d,e,f = addlog2.localPosition
addlog2.localPosition = [d,e,f+20]
hitObj.endObject()
addlog.applyForce(forcer, local)
addlog1.applyForce(forcel, local)
addlog2.applyForce(forcer, local)
if use.positive and logHit.positive:
logObj.endObject()
player['logamount']+=1
# if player['logamount'] > 0:
hud.addObject['log','slot1']
if logHit.positive and player['logpickuptext'] == False:
player['logpickuptext'] = True
scene.addObject('pickuplog','player')
scene.objects['pickuplog'].worldPosition = player.worldPosition
if logHit.positive:
scene.objects['pickuplog'].worldPosition = player.worldPosition
if not logHit.positive == True:
player['logpickuptext'] = False
scene.objects['pickuplog'].endObject()
Anyone have an idea how to get this to work?