Component expected to be of type 'factoryc' but was 'scriptc' (SOLVED)

Hello,

I’m following ‘Getting Started’ tutorial (Infinite frog runner). It was okay until SPAWNING PLATFORMS topic, before STEP 7.

I’m getting this error:

level/controller.script:27: Component expected to be of type 'factoryc' but was 'scriptc'
stack traceback:
	[C]: in function 'create'
	level/controller.script:27: in function <level/controller.script:11>

My level/controller.script code:

go.property( 'speed', 6 )

local grid = 460
local platform_heights = { 100, 200, 350 }

function init( self )
	msg.post( 'ground/controller#script', 'set_speed', { speed = self.speed} )
	self.gridw = 0
end

function update( self, delta_time )
	self.gridw = self.gridw + self.speed
	
	if self.gridw >= grid then
		self.gridw = 0
		
		if math.random() > 0.2 then
			local height = platform_heights[ math.random( #platform_heights ) ]
			
			-- local platform_factory = '#platform_long_factory'
			
			-- if math.random() > 0.5 then
				platform_factory = '#platform_factory'
				print( platform_factory )
			-- end
			
			local platform = factory.create( plaform_factory, vmath.vector3( 1600, height, 0), nil, {}, 0.6 )
			
			msg.post( plataform, 'set_speed', { speed = self.speed } )
		end
	end
end

My level.collection hierarchy:

Does anyone know any clue about what might be causing this?

Thank you!!!

You have two unlucky typos:

  1. factory.create( plaform_factory, … ) => factory.create( platform_factory, … )
  2. msg.post( plataform, … ) => msg.post( platform, … )

Lua handles that as nil, and our msg.post handles that as assuming you mean the current script.

A good strategy of fixing these issues is to print() the unknown, in this case the receiver of factory.create to see if it is what you expect. When you do this you should make a habit of copy-pasting instead of retyping the code, to catch the typos.

7 Likes

OH GOD, I print variable retyping the code, so I didn’t catch the typo. I checked, and rechecked many times kkkk. But thanks for the help. Five years in software/game development and I still fall in these traps.

1 Like