duplicating objects

Hi there

I having problems duplicating multiple instances of an object on a hidden layer to a visible layer. I can only copy one instance of the object. Maybe I’m placing them all in the same location? :smiley:

Here is my method

the hidden object is on layer 5
an empty on the visible layer with the following code attached reads the the coordinates from a text file.
the empty has an ‘edit object actuator’ which then adds the single object to the scene.


# alien dispenser script
# make sure layer 5 is hidden!

cont = GameLogic.getCurrentController()
own = cont.getOwner()

if own.first_run == 1:
	own.first_run = 0		
	
	alien_dispenser = cont.getActuator('alien_dis_act')
	
	print 'attempting to open test file'
	text_file = open('C:\Fob\Blender\Scenes\Data\level_test.txt', 'r')
	
	alien_xyz = [0, 0, 0]	
	
	for line in text_file:
		own.alien_count += 1
		# for each line extract the x,y and z coords into a 3 element list
		result = line.split(' ')
		# remove '
' from z coordinate and convert string to integer
		alien_xyz[0] = int(result[0])
		alien_xyz[1] = int(result[1])
		alien_xyz[2] = int(result[2])
		
		# scale up game index coordinates to world coordinates
		alien_xyz[0] = ((alien_xyz[0] * 2) + 1)
		alien_xyz[1] = ((alien_xyz[1] * 2) + 1)
		alien_xyz[2] = ((alien_xyz[2] * 2) + 1)
		
		print alien_xyz
		
		own.setPosition (alien_xyz)

thanks for your help in advance!

ok figured it out myself.

the GameLogic.addActiveActuator(alien_dispenser, 1) only gets called once per frame? I added properties to the objects to be duplicated to keep track of them over multiple frames. See the code below. I hope it’s useful to someone!


# alien dispenser script

cont = GameLogic.getCurrentController()
own = cont.getOwner()

if own.first_run == 1:
	own.first_run = 0		
	
	alien_dispenser = cont.getActuator('alien_dis_act')
	
	print 'attempting to open test file'
	text_file = open('C:\Fob\Blender\Scenes\Data\level_test.txt', 'r')
	
	alien_xyz = [0, 0, 0]	
	
	lines = text_file.readlines()
	
	own.alien_count = len(lines)

	text_file.close()

if own.line_count < own.alien_count:
	result = lines[own.line_count]

	# scale up game index coordinates to world coordinates
	alien_xyz[0] = int(result[0:1]) * 2 + 1
	alien_xyz[1] = int(result[2:4]) * 2 + 1
	alien_xyz[2] = int(result[3:5]) * 2 + 1
		
	print alien_xyz
	
	own.setPosition (alien_xyz)
	
	GameLogic.addActiveActuator(alien_dispenser, 1)
	
	own.line_count += 1


actuators can only be pulsed once per frame, you aren’t really calling them