Please, help me to make choice in TypeScript.
I use GUI.HUD.showChoicePanel function. I want that the answer1 runs one function, the answer2 runs another function. How to write this? What should the syntax be?
this my code hope is work . you just need replace funtion1 and funtion2
function oWo (){
GUI.HUD.showChoicePanel({
question:“choice”,
answer1:“1”,
answer2:“2”,
onAnswer: answer =>{
if (answer == 1){
function1()
}else{
function2()
}
}
})
}
You can take your cue from the example provided in the docs:
GUI.HUD.showChoicePanel({
question: 'This is your question.',
answer1: 'First answer.',
answer2: 'Second answer.',
onAnswer: answerIndex => {
Debug.log(`Answer ${answerIndex} selected!`)
}
})
${answerIndex} gives you the number of the answer chosen, ie, if I choose answer1, ${answerIndex} will be 1.
So you can use the code above which @HenryHuy has given, but change the condition so that you’re matching the index only (and don’t have to change the value if the answer changes):
GUI.HUD.showChoicePanel({
question: 'This is your question.',
answer1: 'First answer.',
answer2: 'Second answer.',
onAnswer: answerIndex => {
if (${answerIndex} == 1){
// do something
} else {
//do something else
}
}
})
Hope that helps! Let me know if you have any further questions.
Geoff @ TechLeap
1 Like