If you have multiple tools, you might also not have the extruders assign in order (example extruder 0 assigned to tool1). You might also have two extruders assigned to one tool. In these cases, you need to use look at the tools section of the Object model where you can find an array of objects in tools.extruders. For each tool, the array maps that tools extruders to the move.extruder number.