Calculate text from a numeric result

dear MC Community,

How can I output a text from a numeric value?

My smoke addiction calculation works. Depending on the addiction level which is a number, a text, i.e. an adjective should be output accordingly.

Example message in the app:

Your score:
On a scale of 1 (low addiction) and 10 (high addiction), your score is $addictionScore

The value of $addictionScore is determined correctly here.

But now I want to display this value as text and make a statement from it:

Example message:

Based on your statements, a $smokingAddictionLevel Addiction can be determined.

Instead of where the variable $smokingAddictionLevel is located the expressions “low”, “medium”, “high” and “very high” should appear depending on the result of $addictionScore.

My $smokingAddictionLevel calculation does not return the text. What is wrong here?

Hi Ramo,

I would use either Approach 1 here … (made it simple with 2 ranges but you can, of course, also use a rule sequence like < 2, < 4 < 6; in the latter approach please tick always “Leave this decision point after this rule if the rule result is true”))

or this Approach 2 here…

I have tested both and it worked in the latest version of MobileCoach (2.2.17).

BTW: The “store result to variable” is always $smokingAddictionLevel in the “create text” rules

We may need to cross-check with our team why the [1-2] syntax is not working (it is a correct regex).

Would the score be also something like 3.4? Then, I would go for Approach 1.

I hope this helps at least for your next steps.

Best,
Tobi

1 Like

dear Tobi,

Thank you for the quick reply and detailed presentation. I decided on the second Approach. It works well! I learned something new again!

Thanks
Ramo

You’re welcome! :+1: Best, Tobi

Hi Ramazan,

Thank you for your question.

When the java regular expression is [0-10], it matches only the values 0 and 1. That is, 0-1 is taken as a range and not 0 to 10. That could be the reason why you did not get intended results.

You can try out your regex here https://www.freeformatter.com/java-regex-tester.html.

Best,
Prabhu