Hello-
I am trying to learn how to make a basic guessing game for a caller, where the caller would choose a number between 0 and 9 on their keypad and see if it matches a variable that has already been set. I cannot get this to work.
I set a variable called RandomNumber (type String) when the call comes in, and then the caller is prompted with "Please choose a number between zero and nine." The caller chooses a number and that number is stored in a variable called Keypad (type String).
I then have a decision task that reads: Task.RandomNumber==Task.Keypad. The "Yes" branch plays "You are correct" and the "No" branch plays "You are wrong". I set the RandomNumber to randomInt(0) to always get a zero. When I press 0 on my Keypad I always get the "No" branch. I am clearly missing something. Does anyone have any advice on what I need to do here? Thank you!
On the success path before the decision can you add an update participant action and set an attribute to Task.KeyPad and another to Task.RandomNumber and a third to Task.RandomNumber == Task.KeyPad
Just to confirm the values you are actually working with during the decision block?
Hi Anton, thanks very much for replying. I am unsure how to add what you recommend. I did some fiddling around and I was able to make a call flow where I set a variable (type Integer) as RandomInt(5) and then use multiple decision tasks to check if the value is zero through 5. This did work. So I realize my issue is understanding how to compare a digit stored in a variable from call input to a predetermined number. I have had success comparing Integer variables, but I do not know how to convert a caller input variable to an Integer.
I figured it out. In the beginning of the call flow when I set the random number, I needed to create a variable (type String) and set the value to: ToString(RandomInt(5)). Follow that with the caller input variable (type String) and I was able to successfully implement decision tasks for my guessing game where the caller is asked to "choose a number between zero and five".
Here's what I did for choosing a number between 0 and 9. I'm sure there are better ways to do it.
Hi @bschell, Sorry I have been away for a week.
You can do 1 to 5 with RandomInt(4) +1
One way to tidy that up a little is to use a switch instead of nested decision blocks
Or better yet just use a string builder
Full flow
String Task.Answer ==

Then play audio
Hi Anton, thanks so much for replying. I could not figure out how to implement the switch statement. Would you mind providing a quick example? Also I didn't know you could have a variable value read as text-to-speech; thank you that is super helpful.
You certainly can have a variable read as text to speech.
If you are going down the switch path, from the toolbox, under logical select switch
Change to Take path of first case that matches an expression
Just put in your Answer Variable without an expression
Then box for change cases to string will appear, press that
Now just put in the values, 1 2 3 4 5 etc
And put your play audio under each case
Hi Anton,
Thank you very much for explaining this. This is so much easier. Really appreciate it. Have a good day.