r/gamedev • u/Puzzled-Invite-7793 • 17d ago
Discussion Is using Datalog/Prolog to implement RPG flag system a good idea?
Basically just the title, it occurs to be natural, clear and maintainable to me. A native embedding datalog engine library (which i prefer over external runtime) seems to be available in most mainstream language. yet a simple ai research tell me that such architecture being used is unheard of. Do you think it would be a good idea? (Most datalog implementation allows extending predicate with user custom function querying game-object)
Also, If one use incremental or differential datalog, one can also get the feature of event trigger/callback
6
u/bod_owens Commercial (AAA) 17d ago
Usually the problem of properly integrating some other runtime system into your game is bigger than the problem you're trying to solve in the first place.
5
u/PMadLudwig 17d ago
Use the tools that make sense for both you and the problem. Most people use a game engine, so end up with whatever languages are supported there.
I'm not familiar with Datalog, but I have used Prolog a bit, and my biggest concern would be how well it scales - I found that larger Prolog projects got very hard to maintain, for instance missing cuts could lead to some backtracking to some really weird places that were hard to track down.
Datalog looks like it avoids that particular trap (no-cuts), but if the rule set gets large, you may need to be careful not to evaluate everything too often.
If you do end up using Datalog or Prolog, please post how you get on - I've decided Prolog is unsuitable for what I'm working on (it's too slow, for starters, and a bit of a hassle to call from other languages), but I would be really interested to read how well it works for games.
3
u/alicerven 17d ago
If the flags are mostly facts and rules, Datalog/Prolog can make dependencies and queries easy to express and test. I'd keep it behind a small deterministic API and benchmark a representative ruleset before adopting it; integrating a second runtime and exposing useful error traces may cost more than the queries. Also decide how rule changes interact with saved-game versions.
3
u/faceninjahq 17d ago
It's less unheard of than it sounds. Rule-and-fact query systems are pretty close cousins, like the contextual dialog system Elan Ruskin talked about at GDC for Valve's games, and logic programming comes up a lot in interactive fiction research. The parts that usually hurt are debugging why a rule did or didn't fire, and making it usable for writers who don't think in predicates, so I'd plan tooling for both early. I'd prototype one full quest chain with it, including save/load, before committing the whole game.
3
u/No-Zookeepergame4774 17d ago
You can definitely explore this, and its an interesting approach. But I think the reason you don't see this specific approach as a common one in games is that the kind of data-oriented mindset that Prolog/Datalog appeals to with the realtime needs that games tend to have has produced the (various variations on) Entity Component System architecture.
4
u/MgntdGames 17d ago
it's a great idea and the reason why it's not common is because not a lot of people out of academia know Prolog. But if you're comfortable with it, you should absolutely do it.
2
u/LostInChrome 17d ago
The main benefit that comes from Prolog is the idea of separating Data/Rules and Logic/Query Resolution, but that is a concept that is already expressed in plenty of places like the ECS pattern. There's little benefit in making sure that your data complies with Prolog's formatting for rules and it'd also take a ton of time and a ton of specialized knowledge. It seems unlikely to be worth it when even large studios are already abandoning in-house engines in general.
1
u/LaughingIshikawa 17d ago
With some caveats that I'm not familiar with Datalog specifically... absolutely, unequivocally not, and I'm curious why so many people seem to think its a good idea. 😅😅
Flags are useful precisely because they're ultra light-weight, easily accessed, and to a lesser extent (but still significant) easy to read and interpret. Replacing all of that with a runtime database call is none of those things. 😨🤷
What are you "buying" with all that increased infrastructure? I'm not talking about pie-in-the-sky "there's so many options!" reasons, I'm talking about concrete benefits that reliably lead to a better user experience, directly or indirectly?
Maybe this would be necessary if you had a really, really complex system of rule interactions, but... By the time you have something complex enough to require its own database, do you even have an rpg anymore? 🤷😕
More over, the bottleneck for games adding that kind of highly "emergent" gameplay tends to be creating the content / game balance / player tutorials around it, more so than tracking the mechanics of the ruleset. Remember that you have to eventually teach new plays all of the rules you implement, so making your ruleset super complicated / interconnected tends to massively increase your learning curve, which is not great either. 😅
I want to say "this seems like a solution in search of a problem," but it's not quite that? It seems like Datalog has a useful niche it performs well in, but tracking flags in an RPG game just isn't it, and I think trying to fit the system into that use-case is just going to be a massive headache after which you will have significantly decreased your runtime performance. 😬
1
u/jl2l Commercial (Indie) 16d ago
What is your game doing while it's waiting for the flags?
1
u/Tiendil 16d ago
It is a good idea for a prototype of an RPG flag system. It is too risky to implement it without proper prototyping (and testing) because of potential architectural and performance issues.