There is an old military adage by Carl von Clausewitz that states "No plan survives contact with the enemy". Gamesmasters the world over know that this principal is also true for back story development of RPG Worlds, and can be stated as follows: "No back story survives contact with the Players". This is particularly true when you are playing in "Sandbox" mode, which means the Gamesmaster endeavours to provide the Players with the ability to go anywhere in the world and do anything they can think of. The ideal often turns out to be shockingly unlike the reality. What happens? Well, Players do the damnedest things.
A typical (albeit hypothetical) example is when the Gamesmaster has created a trap in a dungeon complex designed by the Antagonist NPC that the Player Characters encounter. The Players have Characters who have sufficient skill to discover and disarm the trap. The back story has it that the villainous dungeon maker intends to keep people out of his precious dungeon and safeguard its treasures. So he devises a trap that makes sense for that purpose. The Players, however, don't quite catch on to the fact that the dungeon before them could be trapped. They trot in like a troop of prancing ponies ready to conquer and loot. They forget that the thief character is there for a reason because they're so excited about getting at the monsters and the loot. So they dance into the corridors and lo - the trap is sprung and someone 'gets it'. Maybe even the whole group 'gets it'. Well, at least according to the dratted trap design which made so much sense in the back story.
And that's the rub. The Gamesmaster was expecting the Players to remember that they have a thief for a reason, but they forgot. Woopsie. And so what happens? Instead of a minor event where the thief was sent ahead and smartly found and removed the trap, gaining experience and saving the party from disaster, the Players forgot, and suddenly the trap is sprung. Dice are rolled, the damage is bad. If the trap was deadly, as logically, given the back story, it should be, then the damage is very bad. And moreover the story, instead of being fun and exciting, becomes a dead end of hopeless carnage.
The problem of course is that the Gamesmaster is in a bad spot. The choices are as follows:
1) the villains never come up with particularly deadly traps.
2) the particularly deadly trap doesn't quite work as designed when sprung.
3) the Gamesmaster hints to the Players until someone remembers to send the thief in first.
4) the Gamesmaster fudges the roll so the damage isn't too bad and the story isn't ruined.
5) the Gamesmaster lets the Players forget the thief, spring the trap and allows the story to end in tragedy.
None of these options is very great. What is greater, from a Story perspective, is when the Players play smart, and remember the thief, and save their party from disaster. However, one could argue that in the real world people are not that smart and a lot of expeditions have ended in tragedy because someone forgot something important like sending the thief forward to search for traps. And thus, it's ok for the story to end tragically because - well, sh*t happens, and a sudden horrible end can be amusing in it's own right. Some Players however may disagree. Of course.
It should also be noted that in this example the thief not being sent forward might have not been an oversight or forgetfulness at all. It could be because in a previous encounter they were attacked from the rear, for example, and so they decided very deliberately to avoid this by having the thief stationed at the back where he can listen for encroaching enemies. One thief, they point out, can not be on guard in two places at the same time.
The Gamesmaster is in a bad spot anyway. When you create a World you want to design it in such a way so that the back story makes sense. You don't want to be constrained to saying "My villains are universally idiots who can not plan a decent trap". You don't want to fake-out that the trap is broken because it doesn't make sense for the back story either - what is the point of having clever villains who parenthetically can't implement a trap correctly so that the Player Characters can still win when they went ahead and made a bad decision (in the context of this particular scene), or worse, forgot. You also during play don't want to give the Players 'hints' about what they *should* be doing because in some sense it ruins the fun. The reason being that it is a lot more fun when the Players make smart moves that save themselves from disaster, than being hinted at, cajoled, and otherwise pampered into making the "better choice". Of course the Gamesmaster could fudge the roll. And this, I think, is the most common response to the situation. If the roll doesn't "feel right", the Gamesmaster hides the roll, and decides against it. Or rolls again without explaination taking the second roll. For some, however, this won't work because in many games the Gamesmaster rolls everything above the table, with the odds sited before each roll. I play that way in my game because it's more fair, and lets the Players know I'm not cheating. Some Gamesmasters, though, have no problem with the idea that cheating is not a vice in RPGs. No problem, but that doesn't work for everyone.
The last option is for the Gamesmaster to let the Players fail. Ouch. That, from a Story perspective can be the worst option. But from a Game perspective it can be the correct and best option. Later, with their next Characters the Players will play better, and smarter, having learned their lesson. Presumably.
So this leaves the question: what takes precidence, good story, or good gaming, in an RPG? Well, the answer to that can be either, depending on what the group values most. It can be that both are equally weighted. And one can not but notice that in some sense the gaming aspect can reflect upon the story aspect. This happens when the Players pay careful attention, think through what they are doing before they do it, maximize their chances of success to the degree their Characters would, and then act.
All in all, it comes down to the fact that Gamesmastering is a challenging art, and so is Playing. To wind up with a good Game AND a good Story is the challenge, and it requires smarts on everyone's part. Even the villain's.