Assuming I would like to build a fitness app and I have implemented a mobile app that measures the number of kilometers walked by the user. How can I translate these kilometers to reward points (assuming 10 points per kilometers). The value of the kilometers variable is measured by the native mobile app and is stored and updated remotely at the server side where the whole user profile is kept.
Hello George, and welcome to Playlyfe Forums.
UPDATE: Now, you can create and associate variables with rewards in the Playlyfe UI itself. And it's pretty smooth too:
- Create an action, open up its advanced settings and create one or more variables & save the action.
- Now, edit the action, add a reward of type Formula. Press Ctrl+Space to bring up the autocomplete which has a list of variables you can use for the reward. Select the
Kilometer
variable, and then type * 10
and press Create.
Watch this super-short video to see it in action:
That's it.
That's a good question. You can definitely do this using the Playlyfe API. It's an undocumented feature right now, but I'll be explaining you the nitty-gritties here.
This feature is possible with the "Actions" components. Actions have variables, which can take custom inputs from the app.
On the API, you can create an action as so:
{
"id": "running",
"name": "Running",
"variables": [
{
"name": "kilometers",
"type": "int",
"required": false,
"default": 0
}
],
"rules": [
{
"requires": {},
"rewards": [
{
"metric": {
"id": "points",
"type": "point"
},
"verb": "add",
"value": "$vars.kilometers * 10"
}
]
}
],
"requires": {},
"image": "default-action"
}
Which basically means:
- define a variable with the name
kilometers
of Number
type.
- The reward uses the variable
kilometers
and gives 10 points for every integral kilometer run.
There is one thing to keep in mind that Playlyfe only deals with integral numbers, i.e., 1, 2, 100, etc, but does rounds-off all floating point numbers, like 1.4 -> 1. So, if you're dealing with kilometer readings such as 1.4, then you can choose a smaller unit such as meters or hectameters (100m) to turn your distance readings into integers before passing it to Playlyfe.
As always in gamification, there are mutliple ways of doing the same thing. One more possible way is covered in our Action Manual over at the Developer Center. Have a look at the linked article.
Hope that answers your question. If there's anything you want help on, let us know, right here!
Cheers.
but how to pass these variable using java sdk to play lyfe any one can help me?
Hi @Pankaj_Palkhade. You can pass this from Java SDK to Playlyfe when you call the "Evaluate a Custom Rule" route.
See here for more details, and select your language to JAVA to see an example.
https://dev.playlyfe.com/docs/api/v2/admin.html#/POSTRuleEvaluateACustomRule