# SpriteSorting and Layer changing

**URL:** <https://forums.solar2d.com/t/spritesorting-and-layer-changing/327795>\
**Category:** Million Tile Engine\
**Created:** [August 14, 2014, 3:27pm UTC](https://forums.solar2d.com/t/spritesorting-and-layer-changing/327795 "2014-08-14T15:27:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![marcelvdmade](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/m/b4bc9f/32.png) [@marcelvdmade](https://forums.solar2d.com/u/marcelvdmade)\
**Post date:** [August 14, 2014, 3:27pm UTC](https://forums.solar2d.com/t/spritesorting-and-layer-changing/327795/1 "2014-08-14T15:27:34Z")

</div>

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:

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

&nbsp;&nbsp;&nbsp;&nbsp; scene.lua:75: in function \<scene.lua.73\>

&nbsp;&nbsp;&nbsp;&nbsp; ?: 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 🙂
