Scotty's Rank???

Has anyone ever noticed that at the end of Star Trek III Scotty’s rank was a full Captain, then in Star Trek IV he was a Commander, and then back in Star Trek V he was a Captain again???

Costuming error maybe?

For the entire movie? Probably… but even as a kid it always bugged me for some reason.