paranim / pararules

A Nim rules engine
The Unlicense
139 stars 3 forks source link

Clear facts from session? #2

Closed arunvickram closed 3 years ago

arunvickram commented 3 years ago

Hi @oakes,

I was wondering if there was a way to clear all facts from the session? IIRC pararules is generally supposed to be the driving force of the engine as it's kind of a replacement for ECS, but I'd like to keep it restricted to the turn based RPG battle mechanics I'm developing, as I'm integrating my Nim code with the Godot engine. I was wondering if there was a way to do something like:

session.clearAll()

So that the facts don't stay in the session after leaving battle?

oakes commented 3 years ago

Not at the moment, but i suppose you could deepCopy your session right after creating it and use that when you want to restart. Right now the retract proc requires a specific id + attr.

oakes commented 3 years ago

I just realized, there is in fact a way to clear all facts from the session :D Try this:

for fact in session.queryAll():
  session.retract(fact.id, Attr(fact.attr))
arunvickram commented 3 years ago

Hey sorry, I've been busy with work; I'll try that tonight or tomorrow!

arunvickram commented 3 years ago

So i tested it in a blank project and it works!