Shape, diameter, depth and drive type of the head (slotted*, philips, torx, square, etc), thread length on the shank, shank tip, thread angle, color, metal of which it's made (you don't want a screw that's going to rust in place due to galvanic action), hoo boy, it can go on and on, and you're quite correct if you're implying it's not that easy to perfectly match a screw. Sometimes it has to be good enough to just work, and not be a perfect replacement. But even the "gun screws" don't necessarily work. I bought such a screw for $2.79 as a replacement set screw for one of my Enfields' cocking piece's firing pin retention, and while it was the proper size and thread pitch, and screwed in just fine, the head was too small!! So I had to order a reproduction replacement screw for something like $12, including tax and shipping, from Numrich. For one little screw!!
*and slotted gun screws generally don't have the same slots as ordinary screws, which is what sometimes gets people in trouble when they use ordinary slotted screwdrivers to drive them.