Closed ertugrulcetin closed 2 years ago
This could be compared to the salience feature in clara. I've thought about it before but i couldn't think of a good use case. Are you doing rendering in your rules? I have't found any advantage to that; ideally rules only update the state, and then afterwards you could query the session for data and do side-effecting stuff like rendering. Ideally order should not matter unless there is a dependency in the data expressed in the :what block.
Ideally order should not matter unless there is a dependency in the data expressed in the :what block.
@oakes Could you show me an example of this please? - how to construct dependency order in :what block
A dependency occurs when a rule receives a fact in its :what block that some other rule inserts. If you made a rule that received ::player ::x
, then it would be "dependent" on ::move-player
, and would always run after it.
So, if you need rules to run in a certain order even though they don't have any dependency between each other, then i assume you are trying to do side-effects like rendering in your rules. Is this true? Because i want to know the use case for something like this.
you are trying to do side-effects like rendering in your rules. Is this true?
Yes, that's true. In the game loop, I need certain order.
Here's how i do it in an example game:
Each tick of the game loop, i fire the rules and then query the data i want afterwards. Keep in mind that query-all
is very fast because it's just returning the matches that were already computed; the real work is being done during fire-rules
. I guess it can sometimes be convenient to do things inside of the rules but i think you'll find that keeping state changes separate from external side effects (like rendering, playing sounds, etc) will end up being cleaner in the long run.
Thank you so much for the explanation!
First of all, thank you for creating this library! When building games there is render loop and sometimes we need to execute functions in some order so I needed it and created this PR.
o/->session
takes an extra parameter which is calledpriority-map
.Run this multiple times;