Guns, gunpowder, and firearms have been around for quite some time. Gunpowder first showed its face in China around the 9th century, then spread to the Middle East and Eastern Europe until finally reaching Western Europe sometime after the Crusades. Firearms have existed in some form as well ever since the Chinese Empire of the (Southern) Song mass-produced hand cannon — handheld (heavy) gunpowder-filled tubes — as an improvement upon the hand-grenades already in use by militiamen in urban garrisons c. 1232, though this wasn't enough to change the course of their century-long losing war against the Mongols. And in 1364, we have the first recorded use (by troops of the Mongol-led Chinese Empire of the Yuan) of shooter-lit wicks by hand that ignited gunpowder that was loaded into a gun barrel — the matchlock arquebus. So guns actually had a place in the medieval world and are not a purely modern phenomenon. So why do Fantasy fiction and RPG developers treat it like a Red-Headed Stepchild? In their worlds, guns don't exist. Cannons maybe, crude gunpowder bombs possibly, rockets if they're having a good day... but no handheld guns (unless the work in question involves werewolves, in which case Silver Bullets may appear).
There are three main issues tied with this trope.
Mix and match troopers.
It's frequently attributed to the assumption that guns ended the era of knights; while it might be that creators of works of fantasy think this, the assumption itself isn't true. Guns and armored horsemen existed side-by-side for over 300 years. After the advent of guns, armorers would deliberately shoot at their armour — and customers would look for the dent because it indicated that the armour would stop bullets. That's the origin of the term 'bullet proof' — the armour was proofed (tested) against bullets. Early guns were not necessarily superior to traditional projectile weapons in every respect. They were more like crossbows, point-and-trigger weapons with a low rate of fire (and initially used a trigger mechanism borrowed from them). In fact, an English officer seriously suggested in the late 18th century (i.e. around the time of The American Revolution) that the Redcoats go back to the longbow, for the superior rate of fire. He was ignored, of course, as the superior lethality, accuracy, and moral shock of the musket made it far more useful on the battlefield than the longbow—to say nothing of the shallower learning curve (it takes months if not years of training to learn to use a longbow; basic musketry can be learned in a matter of weeks) and less-demanding physical requirements (it takes a lot of effort to draw a longbow; hardly any to squeeze a trigger).note
The real change in warfare was the Swiss introduction of pikes in the 15th and 16th centuries — much like the Greek phalanxes, but the Swiss were much more known for charging with them. They were first stopped by the fittingly-named Francis I of France, who used field fortifications — and musketeers.
Knightly charges had been showing vulnerabilities for some time before this happened, though. They were a widespread tactic in the Medieval age, as it was a long-established tradition dating back to when Frankish and Anglo-Saxon chiefs/kings would smash poorly-equipped infantry whilst on horseback surrounded by trusted warriors. Although some nations still maintained effective disciplined infantry (Anglo-Saxon England, for one, and the core of it was kept intact by the Normans), it generally required a large body of professional soldiery that didn't exist. Although cavalry had long proved their worth and was easily provided by the feudal/manorial social system of the time, cracks appeared by the 'High' Middle Ages. They were only dubiously useful in the Crusades (11th through 14th Centuries), and useless against the Mongols, as both the Mongols and the Turks used light cavalry and didn't field solid ranks of troops. Longbows had difficulty penetrating plate armor (the difficulty dependent on the bow and armor), contrary to popular belief, but Crécy and Agincourt did reveal further problems — at Crécy (1346), the French lost because their horses had no barding armor, and so had no protection against arrows, but at Agincourt (1415), they lost because they did have barding armor, and so got stuck in the mud. Worse still was the introduction of very literal tanks five centuries early in the Hussite Rebellion (1415-1436) — the Bohemians (modern Czech Republic and Slovakia) invented the wagon circle to defend against Hapsburg knights, and attacked with massed wagons carrying light cannons and ten or twelve peasants with flails. They won, by the way; moderate Hussites had religious freedom in Bohemia until the Thirty Years' War (when they got caught up in the Catholic-Protestant wars that had begun with the Smalkaldic War of 1525 and were annihilated).
So, in short, knightly charges were dead without needing firearms to kill them; they did, however, speed up the process of their demise as was seen in the battle of Pavia (1525) which a decisive victory for Charles V of Habsburg over the aforementioned Francis I due to the introduction of the Tercios, a unit that combined the firepower of the arquebus (and later the musket) with the reach of the pikes and the versatily of the swordsmen; the result was a massacre of the French cavalry and the capture of the king of France, cementing the return of the prominence of infantry in the battlefield. Personal firearms (including cavalry pistols) were if anything more useful in countering the new styles of heavy infantry; before long, though, the musket meant the conversion of knights into cavalry (not necessarily noble, and taking orders from the general rather than acting largely on their own), and the relegation of pikes to uselessness except in defending against cavalry attack. (The Janissaries managed to fight with musketeers without using any pikemen at all.)
Although plate armour was worn up till the middle of the 17th century, improvements that led to increased muzzle velocity and higher bullet calibre rendered it pointless to have without making it thicker and heavier, which was just not practical. That's why you see pictures of 17th-century troops in metal breastplates and helmets, whilst by the 18th they'd largely abandoned them, though some heavy cavalry units retained breastplates and helmets that were more intended to deflect swords, bayonets, and low-powered or ricocheted bullets as opposed to a solid hit from a foot soldier's musket. Breastplates and helmets for infantry wouldn't return until World War I, when the sheer quantity of shrapnel put out by modern artillery (plus the technique of indirect fire that allows one to deliver said shrapnel even if you can't see where the shell will land) brought both back (often based on medieval designs; compare the kettle hat to the Brodie and Adrian helmets or the sallet to the iconic Stahlhelm).
The use of mixed pikes and firearms (pike-and-shot) continued for quite a long time, but by the end of the 17th century, the arrangement had more or less disappeared. The reasons were the increased use of musketeers in formations, a change brought by Maurice of Orange and Gustavus Adolphus of Sweden; and the widespread adoption of an innovation that came from (according to legend) an ingenious blacksmith of Bayonne, France, who realized that a gun was basically a pike-staff that could shoot bullets. Attach a blade to the end of a gun (called a bayonet to this day), and voila, you have a serviceable spear. After some problems — like how to remove a blade that you inadvertently jammed in your gun — were ironed out, bayonets were more or less standard issue in European arsenals. They still remain in use today, though more as a utility knife and a training tool for aggression.
Never bring a gun to a sword fight.
Of course, there are also dramatic reasons for this trope.
As cool as gun fights can be, they just can't accomplish the level of intensity of a one-on-one duel with swords. If a hero has a gun, he can just shoot the villain from afar. But with swords, they can get up close and personal, engage in witty banter, look each other in the eye, and, if one gets that fatal cut or thrust in, engage in the drama of watching the other die. This is why even modern-day Action Movies will often have their final showdown be a hand-to-hand confrontation between the hero and the villain rather than a gun fight.
Another reason can be that guns are too impersonal in a fight, as they are often associated with formations and the mechanical killing of the enemy by volleys of fire; to be fair, this type of fighting is also true of the armies of Classical Antiquity, as well as those of the first half of Late Antiquity and the Early Modern Era, it was why Rome managed to win time and again against their barbarian enemies.
The reason may also be that guns are too modern. They're the primary weapon of choice in the real world. If fantasy authors want to achieve that escapist, ancient feel in their story, they have to use ancient weapons. Guns don't have that level of romance. This could also be the reason why Automatic Crossbows are excused despite being functionally similar to guns. There is also the widespread perception that guns take all the "skill" or "honor" out of fighting and make the heroes look cheaper: no intensive training with ancient masters, just "BANG! He's dead."
This is also the reason for the Gun Fu trope, as authors mix hand-to-hand combat tropes with gunplay in an attempt to capture the choreography lost from using a gun instead of a sword.
One is only left to wonder if some long time in the future, where they fight with yet-unimaginable weapons, it's going to be guns that carry the "oldie but goodie" flavor of cold steel in today's fiction.
Ready, aim... fireball!
May or may not be justified in Magitek settings. Why bother with explosives when you can blow somebody up with a fireball? Because anyone can use a gun, but not everyone can throw fireballs. This is a common issue of technology versus magic: technology works for people who haven't spent years studying the sacred mysteries. (The same problem exists for longbows.)
But if the magic trinket can be activated by anyone, why bother with explosives when you can blow somebody up with a fireball from a wand? 'Point, say the command' is just as simple as 'point, pull the trigger', assuming a wand doesn't just need a thought to activate, which in itself is advantageous. With greater power and availability of magic, this becomes less and less of a problem. In other words, why bother with a gun that's heavy, has limited ammunition, and can possibly end up jamming when you can use a little inconspicuous stick that has limitless shots and can be used for a variety of functions aside from killing? Especially true if the setting can have small wands or similar magical trinkets capable of mass destruction. The same can't always be said of guns unless they're some kind of Magitek. This is the reason that, for the most part, guns aren't used in the Eberron setting of D&D (although they do exist).
- In a lot of settings, even ones that don't deal with magic vs technology or Magitek, magic is rarely that easy or practical. Activating trinkets might require a large degree of knowledge or skill (for example, in D&D, these types of items can only be used by classes that generally would be capable of casting the spell in the item, in many cases better than the item does, or has specialized training specifically in activating these types of items), the items are prone to backfiring (Warhammer loves this — even people with training often can end up killing themselves or allies with these types of items), these items are almost always incredibly expensive, these items tend to have limited charges, and anti-magic defenses are frequently much more efficient than anti-bullet defenses.
Despite all of this, there are writers who are talented enough to make guns work in their fantasy settings and even have them achieve a level of coolness equal to medieval weaponry. Perhaps it's understandable why guns aren't seen much in fantasy settings, but it's still nice (if you like guns in your fantasy) when authors manage to do it. After all, there were not only loosely historical The Three Musketeers, but Baron Munchausen himself used a firearm and it didn't make his stories any less of... what, Heroic Fantasy?
Conversely, assuming that gunpowder must automatically exist once reaching a certain level of advancement is to fall into a logical fallacy; development can happen at different rates in different fields, especially in a world that already has Functional Magic to make long-range destructive attacks. This is particularly the case if the functional magic and/or setting results in tactics differing greatly from the setting in which early guns found their first use in real history: firing in volleys using soldiers marching in ranks on battlefields. Guns present their own set of logistical issues in the form of supplies of gunpowder, as well as the cost of munitions (which severely curtailed the number of rounds of ammunition that gunpowder armies could use in training until the second half of the 19th century).
Or maybe the author outright despises guns and wants to create a world where they — and whatever other technologies the author may think are ruinous — do not exist for that purpose alone.
One historical note apt to be ignored is that the discovery of gunpowder was a major fluke in human history, perhaps the most major one. Unlike many other technologies — like metalworking, stone-cutting, carpentry, and writing — as well as inventions like spoons, swords, wheels, bows, etc., which were independently discovered/invented all over the world, gunpowder was discovered exactly once on accident by people who weren't even looking for it: Chinese alchemists trying to create an elixir of immortality. While eternal life eluded them, they found this gunpowder stuff was highly flammable and, with the right formula, highly explosive. The Chinese used gunpowder weapons in their desperate, losing war against steppe tribes and seized upon them as a way of turning the tide. It didn't work, but they ended up with an effective formula and a series of cheap mass-produced weapons based upon it (chiefly pole-grenades and pole-guns for use in defending against siege-assaults). It didn't take long to spread to India, where local warlords figured out ways to use it in their own wars, and eventually the Middle East, where it was also popular for the same reasons. It even ended up reaching the quintessential backwater of the pre-modern world, Europe, after a while. Of course, none of this is to say that gunpowder wouldn't be invented eventually in most scenarios, but only in more or less in the same sense as the old thing about how infinite monkeys on infinite typewriters would eventually produce the works of Shakespeare.
Justifying the Trope
There are a number of ways to justify the trope, for those that care to take the time, mostly based on engineering concerns or historical analogy:
1. Literal gun control — The main reason that it took three centuries for gunpowder to cross from the Song Empire to Europe was that the alchemical 'recipe' was the equivalent of a state secret in each new realm it spread to. In a fantasy culture, even in the absence of that kind of state control of military technology, the people who do all the alchemy tend to be the same people that work with magic, who are easily motivated to keep it a "trade secret" to avoid competition in the realm of fireball-tossing.
2. Missing ingredients — Saltpeter, especially, can be rendered essentially unavailable by basic changes to biology or terrain. For instance, if bats are magical enough to make wandering through caves collecting guano an extreme hazard to life and limb (not a stretch in D&D-based stories), making the stuff isn't worth the pain even if you know how, and it's certainly not common enough to waste on projectile weapons when you've got perfectly serviceable crossbows. This one can be quite effective if combined with the fourth point below. While bat-infested caves aren't in short supply in many fantasy settings, it is easy to write their use as not being very economical. The other historical source for saltpeter was niter, and with its water solubility mineral sources tend to be less common outside of arid regions. (The other preindustrial method of making saltpeter—extracting nitrates from human and animal waste and then filtering through potash—is labor-intensive and takes a year to get results.) Even if gunpowder exists, one could write a setting where rocketry is more economical, as gunpowder formulae designed for that role can make use of a lower proportion of saltpeter.
3. High explosives happened first — If someone worked out how to multiply nitrate glycerine or toluene before working out a low explosive like gunpowder, society may have skipped over to bombs and given alchemical explosives a reputation for being something you don't want anywhere near your face.
4. They exist, but they're not cost-effective — All it takes is iron being scarce and/or wood plentiful (making bows cheaper as well as better), a military that just doesn't do much naval warfare or siegesnote , or a military and society that just doesn't do much warfare full stopnote and you have very few people using guns. This is exactly how things actually happened, as so spectacularly illustrated by the First Opium War of 1840-42, wherein the forces of two European societies who'd had fought through more than 3 centuries of virtually non-stop gunpowder warfare note faced off against the forces of an empire which (starting from a similar if not greater standard of gunpowder-usage) hadn't fought a siege or naval battle for three centuries. note The result was... predictable.
5. They are out of scope. Medieval guns were more like battlefield equipment instead of personal weapons. They required a piece of burning rope which would first ignite a bunch of gunpowder in an open pan, which in turn would ignite the gunpowder inside the gun. This means you needed a lot of preparation before firing it, and you couldn't really use it while on the move. Also, starting a fire was a lengthy process. The issue with medieval guns wasn't the reload speed alone; muskets in Napoleon's time were just as slow to reload, but you could fire a loaded flintlock musket without any significant preparation. Not so with medieval guns. By the time wheellock and flintlock were discovered, the time we call the medieval era was over. This means all the guns you had in medieval times were a battlefield equipment, used by armies against other armies. However, most fantasy novels and role-playing games are focused on a very small group of adventurers on specific quests, and not on huge armies on an open battlefield.
Dungeons and Dragons, notably, takes a combination of justification 4 and analogy to real-world medieval firearms: you can purchase them, and they're even simple weapons (you don't need to be a soldier to use them), but they're short-ranged, slow-loading, extremely expensive, prone to failure, and not really any more powerful than their wood-and-iron counterparts, though lucky (critical) shots occur more often.
6. Some creatures may be outright immune to conventional weapons, and can only be harmed by magic. D&D is especially noteworthy for having many monsters that will No-Sell physical attacks from ordinary weapons. This applies even to guns, as even modern assault weapons are useless if the bullets can't hurt the target. In these cases, only magic, or weapons that have been charged with magic, will do you any good. This may overlap with guns not being cost-effective, as in item #4 above. A magic sword can be used over and over again, as can magical missile weapons like arrows. However, any individual bullet can only be shot once, which means that you're better off focusing your magical resources on weapons you can keep reusing as needed.
7. Magic is disproportionately effective against guns. Perhaps it's easier to break and jam guns because they have a lot more small moving parts than a sword does, or perhaps mages can ignite gunpowder at long range and blow up ammunition stores.