Reputation: 1
How do I Think/Set a variable only when a button has been clicked. I have multiple buttons in a template and I want to set the value of the variable based on the button the user clicks on. I don't know how to do this without using multiple assignments of the variable with the Think/Set tag and the variable ends up being with the last value assignment.
<category>
<pattern>quiz</pattern>
<template>
Which of these topics are most interesting to you?
<button>
<text>topic1</text>
<postback>question 2</postback>
<think><set name = "question1">1</set></think>
</button>
<button>
<text>topic2</text>
<postback>question 2</postback>
<think><set name = "question1">2</set></think>
</button>
<button>
<text>topic3</text>
<postback>question 2</postback>
<think><set name = "question1">3</set></think>
</button>
<button>
<text>topic4</text>
<postback>question 2</postback>
<think><set name = "question1">4</set></think>
</button>
<button>
<text>topic5</text>
<postback>question 2</postback>
<think><set name = "question1">5</set></think>
</button>
</template>
</category>
Upvotes: 0
Views: 160
Reputation: 905
As you have already seen, you can't set variables within button or reply tags. Instead, you should pass any values to the category itself via the postback, like this:
<category>
<pattern>quiz</pattern>
<template>
Which of these topics are most interesting to you?
<button>
<text>topic1</text>
<postback>question 2 1</postback>
</button>
<button>
<text>topic2</text>
<postback>question 2 2</postback>
</button>
<button>
<text>topic3</text>
<postback>question 2 3</postback>
</button>
<button>
<text>topic4</text>
<postback>question 2 4</postback>
</button>
<button>
<text>topic5</text>
<postback>question 2 5</postback>
</button>
</template>
</category>
<category>
<pattern>question 2 *</pattern>
<template>
<think><set name="question1"><star/></set></think>
You clicked on topic <get name="question1"/>.
</template>
</category>
Upvotes: 0