DEV Community

Travis Elkins for r4nkt.com

Posted on • Originally published at r4nkt.com

Get your streak on...!

Get your streak on...! πŸš€

While this feature wasn't considered necessary for r4nkt's initial release, it was always considered a must-have. Well, over the last week, initial support for streaks has been deployed to production. This makes it very easy for you to define achievement criteria in terms of streaks.

We are very excited to have rolled this functionality out and hope that you and your users will enjoy the new possibilities that are now available.

What are streaks? πŸ€”

In terms of r4nkt achievement criteria, a streak is when a player has performed some sort of action(s) over a consecutive series of time intervals. Some examples:

  • A salesperson has closed at least one sale for 10 days in a row.
  • A student has passed the daily quiz 5 days in a row.
  • A user has walked at least 100 steps 8 hours in a row.

How does it work? 😯

R4nkt's streaks are defined on the individual criteria. The criterion resource has a new property: streak. Like similar properties, it takes a string that matches the following pattern: interval:amount.

The interval can be one of the following:

  • days
  • hours

Both require an amount, which indicates the number of days or hours that the streak should be.

So, if we take some of the examples from above, we can see how easy it is to define streaks:

  • days:10: 10 days in a row.
  • days:5: 5 days in a row.
  • hours:8: 8 hours in a row.

Very simple and straightforward...! πŸ€“

Take it to the next level

For many, the basic use of streak criteria will be sufficient, but when you combine them with criteria conditions and custom data references, then you can really start to come up with very complex and interesting achievements. There are so many possibilities...! πŸ˜ƒ

Imagine that you develop an e-learning application or service and your students are allowed to take a daily quiz. You could define an achievement for students that pass the daily quiz by 95% or more for three straight days.

To do so, you would need your achievement, which we'll call The Triple, your primary criteria group, and a single criterion.

You'll also have an action, which might be called Pass Quiz and give a custom ID of pass.quiz. You will report it whenever a player passes a quiz. And, you'll want to pass the result in the activity's custom data, like so:

"custom_data": {"result": 97}
Enter fullscreen mode Exit fullscreen mode

Then, your criterion will have the following properties:

  • custom_action_id: pass.quiz
  • rule: gte:1
  • streak: days:3

These properties let r4nkt know that the criterion is met when the player has passed at least one quiz each day for three (or more) consecutive days.

But what if they don't get a result of 95 or more...?

Well, that's where criteria conditions come into play. For this scenario, you'll have a criteria condition on either your criteria group or your criterion with the following definition:

"conditions": {
    "groups":  [
        {
            "conditions":  [
                "activityData:result,gte,95"
            ]
        }
    ]
}
Enter fullscreen mode Exit fullscreen mode

So, by defining the activityData criteria condition, you make sure that only activities that have a custom data result of 95 or greater will be considered. This is applied and then the criterion's rule and streak are considered. That is, once all "Pass Quiz" activities for the player that did not meet the criteria conditions (result >= 95) have been filtered out, then r4nkt will look to see if at least one such activity exists per day for three (or more) consecutive days.

That's pretty great, don't you think. 😜

I want to learn more

You can check out our ever-improving documentation or you can also join our Discord server and ask for help or make suggestions. ⚑️

Coming Soon

There are still more streak-related features that are in the pipeline. Obviously, we're going to expand the available time intervals and you will soon have the ability to define streaks in terms of the following time intervals:

  • weekly
  • monthly
  • yearly
  • minutely...? 😜

More may be added, but we'll allow your needs to drive those efforts. πŸ€“

If you want to be notified when these new features are added, if you'd like to suggest one, or if you'd just like to be kept abreast of what we're doing, then follow us on twitter. We'll keep you posted. 😎

Top comments (0)