SpriteSorting and Layer changing

Hello everyone,

We are working on a orthographic project which uses spriteSort to change the depth of different sprites, and we also use different levels on our map. (for example, walking over a bridge or going underneath it)

Now we encountered a problem, when our character hits the object to change to a different level(the level of the bridge) we encounter an error:

MTE\mte.lua:12860: ‘for’ limit must be a number. stack traceback:

     MTE\mte.lua:12860: in function ‘update’

     scene.lua:75: in function <scene.lua.73>

     ?: in function <?:221>

so the ‘for’ which is not a number comes from:

&nbsp;&nbsp;&nbsp; for k = 1, masterGroup[i][j].numChildren, 1 do

because masterGroup[i][j].numChildren has a value of nil.

Here’s the code which calls fore the changeSPriteLayer

elseif key == "changelevel" then self.mte.changeSpriteLayer(self.player, self.mte.getSpriteLayer(tonumber(value)))

Without SpriteSort enabled, this does work however. Does anyone know where the problem could be found? Thanks in advance :slight_smile: