Creating factory objects issue

Hello, I’m very confused about an issue I’m currently having. I had it so the enemies were spawned randomly around the map using this function:

function init(self)
	self.count = 51
	num = math.random(20,40)
	spawnx = 0
	spawny = 0
	spawnPos = vmath.vector3(0,0,0)
	for i=0,50 do 
		spawnx = math.random(-1700,2800)
		spawny = math.random(-1050,1400)
		spawnPos = vmath.vector3(spawnx, spawny, 0)
		enemy_id = factory.create("#enemy_factory", spawnPos, nil)
		--pprint(enemy_id)
	end
end

This works absolutely fine.

I then copied this code and moved it into a different function within the same script and now for some reason it no longer works.

	if message_id == hash("difficulty") then
		self.diff = message.difficulty
		for i=0,50 do 
			spawnx = math.random(-1700,2800)
			spawny = math.random(-1050,1400)
			spawnPos = vmath.vector3(spawnx, spawny, 0)
			enemy_id = factory.create("#enemy_factory", spawnPos, nil, {difficulty = self.diff}, nil)
		end
	end

The only difference here is that I pass data as a property to the factory objects.

These are the errors I am getting.

What is the value of self.diff?

It looks like your enemy script has a go.property of type string, which is not allowed.

1 Like

Yeah it is a string of the difficulty selected before entering the game. How would I pass this information to the enemies then?

go.property can be a number, hash, url, vector3, vector4, quaternion, resource or boolean.

If none of those are suitable, you can use the messaging system to pass a string, or other information in a table.

1 Like