Creating Incomming Questions


Incomming questions are used to get input from a player, they work like a normal message, but include a set of options the player can select like on the BBS. The main differences between questions and normal messages is the formatting of the text file to include the questions, and the call back script, used to get the response from the question.

Incomming questions can be used to create a menu system, which is useful for reducing the number of command slots a script uses, as well as creating configuration menus.

For examples of these, you could check out my Xenon Migration script that uses incomming questions as a config menu, and Capital Ship Crews that uses them to reduce command slots and have all the actions done via Menus instead of commands.


Download Examples:



1. Creating Text files for Questions

The first thing we will look at, is the formatting of the text file to get the question displayed to the user. This is done via the standard text files, help is available here.

Then you need to add questions into the text file. You use the tags [select][/select] to create each question.

<t id="1">This is out test question\n\n[select value="1"]Answer 1[/select]\n[select value="2"]Answer 2[/select]\n</t>

This example has 2 answers in the question. Lets break down the tags, each answer is a single [select] tab.

[select value="1"]Answer 1[/select]

the value is also required, this is so the script knows what answer was choosen in the callback script. Each answer should have a different value string.

The Text between the 2 tags, " Answer 1" is what is displayed in the question box.

one more thing, answers have to be on seperate lines, you cant have 2 answers on the same line, so you must have a \n between each answer. You can however have text between each answer, so you can have something like this

<t id="1">This is out test question\n\n[select value="1"]Answer 1[/select]\nSome text between the answer\n[select value="2"]Answer 2[/select]\n</t>


2. Using the question in a Script

Now u have a text file formated, you use it in the script the same as any other text file entrys. The text file needs to be loaded, usually via a setup scripts. And read using the read text page, or sprintf functions.

Load Text

The only difference with questions and text, is the command used to display them. Its the send incomming question, which is found in the "Audio Commands" menu.

Incomming Question

The first argument, is the text to display, this includes the answers, without any answered defined, it will be displayed the same as a static message.

The 2nd is the important one, its what makes it different from a normal message, this is set to the call back script. A callback script is just another script that you make, when the user selects one of the answer, the callback script is then called, this is the script that controls the answers.




3. Displaying the question

Now you have created the script to display the question, you can just run it to test what it looks like.

Once you run it, you will receive an incomming message which you can view, this will allow you to select the answer you want.


As you can see, there are 2 answers, as you defined 2 blocks of [select] in the text file. The text displayed in each of the answer blocks is what appeared between the [select] and [/select] block.


4. Callback script

Finally, you need to create a callback script, the call back script is the script that is called when a user selects an answer. So, when you select Answer 1, what ever script was defined as the call back script will be run.

The same script is called for all answers, so we need some way to determine what answer was selected by the user. Thats where the select value comes in. In the call back script, you need to define an argument, the argument will be what ever string was entered as the value.

Callback Script

Setting the first argument to "answer" means that the varible $answer will hold the value of the question. If the user selects "Answer 1", $answer will be "1", and if the user selects "Answer 2", $answer will be "2"

The best way to use this, is a simple if statement for each answer.


Then all you need to do, is put you code between the if blocks for what ever you want each answer to do, for the example, this will simply display to the logbook.

If you notice, even thou $answer is a string, the example is testing them as an interger, this is because the question system auto converts the varible into thier correct format. So as you've specificed intergers as the answer values, the answer varible, $answer, will be converted to an interger, so you should test it as an interget and not a string. If you set the value to something like "[select value="answer1"]Answer 1[/select]" then you would test it as a string instead.

if $answer == 'answer1'



<< Prev (Using Message Arguments)