3D colored rooms

I am trying to get an old code to work but I am running into issues. It works except it changes the color of the rooms and it drops off a room or two.

There are 4 rooms, but it drops off a room and 0 should start with 239 not 244. It all seems to come form the python script that looks like this,

Can someone tell me why it is dropping a room and why it is not linking the correct color to the room?
Thanks in advance for any help.