I have modified a multichoice quiz I use in school and would like to add an element whereby the user places a bet before answering. He starts with 200 points and inputs the proportion of this he would like to bet before pressing True or False. If he is right, the amount bet is added to the 200 and if he’s wrong, the amount is taken away, and so on.
The relevant bit of script is this, but I’ve no idea how to change the ‘var pointsToEarn’ element to accept a number from the betting input.
System.useCodePage = true;
var randomNum;
var pointsToEarn = 1;
var pointsToLose = 1;
a = new String(null);
b = new String(null);
c = new String(null);
d = new String(null);
var numOfQuestions;
question = new String(null);
var spotA;
var spotB;
var spotC;
var spotD;
var score = 200;
var index = 0;
if (list == undefined) {
list = new LoadVars();
list.load("questions.txt");
}
gotoAndPlay(2);
1) create a variable for your input text
2) write a function to set your variable
3) call the function when you click on the buttons.
1) to create the variable, you will need to select the input text box, and assign a name to a variable. I used betAmount in my sample.
2) You will need to write a function to set your input text. You notice that I wrapped the betAmount in a Number() so that flash will see the betAmount as a number and not a String.
function setPoints(){
//trace(betAmount)
pointsToEarn=Number(betAmount);
pointsToLose=Number(betAmount);
}
3) on the answer buttons, you will just need to call the function setPoints();