Skip to main content

Right Hand Side (RHS)

In the RHS of a rule its consequences on the state of the game are defined.
Each possible consequence of a rule has an associated method:

  • addBadge(...): this method allows to add a badge to a badge collection and eventually to insert a BadgeNotification into the working memory.
  • completeChallenge(...): this method allows mark a challenge as completed.
  • gainLevel(...): this method allows to insert a new level inside a CustomData.
  • updateScore(...): this method allows to update the score of a PointConcept.
  • insert(...): this method allows to insert a fact inside the working memory.
  • log(...): this method allows to log a message on the console.
  • freeRHS(...): this method allows to specify the consequences of a rule by supplying a String.
Heads up

The freeRHS method should be used only when it is strictly necessary because while using it the main advantages of the DSL are lost (typo checking, autocomplete, etc.).

A full description of the methods can be found here.

RHS Definition

The RHS of a rule can be defined by combining the above methods:

RuleDefinition.java - Fact constraints
import eu.trentorise.game.model.BadgeCollectionConcept;

public static void main(String[] args) {
final String BADGE_NAME = "green-badge";
final BadgeCollectionBind BADGE_COLLECTION_BIND = new BadgeCollectionBind("badgeCollection");

pkg = new PackageDescrBuilderImpl()
.name("eu.trentorise.game.model")
.newImport(BadgeCollectionBind.class).end()
.newRule()
.name("my_amazing_rule")
.when()
.badgeCollection(BADGE_COLLECTION_BIND)
.badgeEarnedNotContains(BADGE_NAME)
.end()
.end()
.then()
.addBadge(BADGE_COLLECTION_BIND, BADGE_NAME)
.log(String.format("The %s badge has been assigned", BADGE_NAME))
.end()
.end()
.getDescr();
}