I do know the question in the title is really stupid, but it is the best phrasing I could come up with. Let's say I am building a circuit and the schematic says to use a BD139 transistor. Would there be any issue in using any other NPN transistor? What would I do if I could not find this transistor? I can't buy any parts online, and I do not have access to a store where they would sell this stuff, so I am limited to what I can salvage from old broken electronics, most of which have older, outdated parts that have limited information online.
Would there be any issue in using any other NPN transistor?
If you are missng a screw, can you add any screw ?
Would it depend on how long is the screw ? What is its thread is? How large is the diameter ? What is the material ?
Similarily, all electrical components have electrical characteristics and parameters. Different components can tolerate more voltages and currents than others. Others are set up for a particular application even though they are all part of the same family of components (capacitors, resistors, inductors, transistors, diodes).
So yes transistors are interchangeable, if the type (npn/pnp) and required specs match.
What would I do if I could not find this transistor?
You compare the parameters for the transistor you can have access too, and compare it to the one in the you want to have. You keep searching until you can find one that can handle it. Now, someone might have used an a transistor that was overkill for the project, and so knowing a bit about the circuit would help. If the current through a transistor was only 10mA and they have a part that can tolerate 1A, well, that's a bit much, and you can find a part that is more suited to what the circuit it. But if you do not have knowledge with how to analyse circuits, then you should probably match the component (to be on the safe side).
In many cases components are not used to the very edge of their maximum ratings so there can be some room to interchange parts that may not fulfil all the specifications.
Often a more expensive, newer or larger component may have better specifications than the original component.
Looking up the data-sheets for the target transistor and any potential replacements will be required to make a decision on the compatibility.
There are hundreds/thousands of common transistors in use and more that are rare, expensive, obsolete/discontinued or foreign.
Often you can select a suitable test candidate based on technology (BJT, FET [enhancement or depletion mode], unijunction transistor, IGBT, MOSFET) polarity (NPN, PNP, N-type, P-type), power handling (case size, wire gauge), gain and gut feel.
Gain of a random transistor can be determined with a affordable component analyser.
Other more exotic parameters (capacitance, frequency response, leakage, voltage drops and saturations, etc) are seldom worth measuring if you have a part number as almost all transistor have on-line data-sheets. It is worth noting that often the marking is only part of the part number or in the case of an SMD components a part short code that corresponds to a standard part number.
If you share a circuit some folk may decide to help you determining the important transistor characteristics you need to look for.
You cannot substitute any, but it is easier to find a replacement transistor than a replacement CPU chip to fit into the slot of predecessor unchanged.
BD139 is a pretty large power transistor (12.5 W with good cooling or short term), NPN, and can handle as much as 80V and 1.5 A. Its current gain can be as miserable as 25 in the worst case and I think most of other transistors of similar kind would handle this. It is not a high frequency transistor.
The substituting transistor must match or exceed these parameters. Without understanding schematics, it may easily be that some other parameters are even very important, but if the device cannot fail in a dangerous way and alternative is just to trash it, I would simply put a best available replacement transistor instead of the dead BD139 and try.