BialyDran Posted November 20, 2017 Share Posted November 20, 2017 Any idea's how to make this piece of code more efficient and / or robust? function ChooseAnswers() if ( guiGetText ( Option[i] ) == npcAnswers[1][2] ) then wayOne() elseif ( guiGetText ( Option[i] ) == npcAnswers[1][3]) then wayTwo() elseif( guiGetText ( Option[i] ) == npcAnswers[1][4]) then wayThree() elseif( guiGetText ( Option[i] ) == npcAnswers[1][5]) then wayFour() elseif( guiGetText ( Option[i] ) == npcAnswers[2][2]) then way1Option1() elseif( guiGetText ( Option[i] ) == npcAnswers[3][2]) then way2Option1() elseif( guiGetText ( Option[i] ) == npcAnswers[3][3][2]) then way2Option1Answer1() elseif( guiGetText ( Option[i] ) == npcAnswers[3][4]) then way2Option2() elseif( guiGetText ( Option[i] ) == npcAnswers[3][5][2]) then way2Option1Answer2() elseif( guiGetText ( Option[i] ) == npcAnswers[4][2]) then way3Option1() elseif( guiGetText ( Option[i] ) == npcAnswers[5][2]) then way4Option1() elseif( guiGetText ( Option[i] ) == npcAnswers[5][3][2]) then way4Option1Answer1() elseif( guiGetText ( Option[i] ) == npcAnswers[5][4]) then way4Option2() elseif( guiGetText ( Option[i] ) == npcAnswers[5][5][2]) then way4Option2Answer1() else outputChatBox("Unknown error. Please report it to admin ASAP.") end end function wayOne() -- end function way1Option1() -- end function wayTwo() -- end function way2Option1() -- end function way2Option2() -- end function way2Option1Answer1() -- end function way2Option1Answer2() -- end function wayThree() - end function way3Option1() -- end function wayFour() -- end function way4Option1() -- end function way4Option1Answer1() -- end function way4Option2() -- end function way4Option2Answer1() -- end Maybe by using CASE? Idk help plz Link to comment
quindo Posted November 20, 2017 Share Posted November 20, 2017 Maybe something like that? local AnswerToFunction = { npcAnswers[1][2] = wayOne, npcAnswers[1][3] = wayTwo, npcAnswers[1][4] = wayThree, npcAnswers[1][5] = wayFour, npcAnswers[2][2] = way1Option1, npcAnswers[3][2] = way2Option1, npcAnswers[3][3][2] = way2Option1Answer1, npcAnswers[3][4] = way2Option2, npcAnswers[3][5][2] = way2Option1Answer2, npcAnswers[4][2] = way3Option1, npcAnswers[5][2] = way4Option1, npcAnswers[5][3][2] = way4Option1Answer1, npcAnswers[5][4] = way4Option2, npcAnswers[5][5][2] = way4Option2Answer1, } function ChooseAnswers() local guiText = guiGetText( Option[i] ) local answerFunc = AnswerToFunction[guiText] if answerFunc then answerFunc() else outputChatBox("Unknown error. Please report it to admin ASAP.") end end Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now