I'm new to Kotlin and I tried to search for a solution but I can't find one. I have these function that is inherited from an interface, and when I try to return the variable to fill up the empty variable it doesn't get passed from info 4. can someone please help me why it doesn't get passed?
class chooseRace(): adventuringBasics {
override val variable: String = " "
override fun PrintOut() {
println("Your race is $variable")
}
override fun info2(selects: String) {
}
override fun info6(lvl: Int) {
}
override fun info3(last: String) {
}
//Race Selector
override fun info4(type: Int):String {
when (type) {
1 -> variable == "Human"
2 -> variable == "Orc"
3 -> variable == "Elf"
4 -> variable == "Demon Kin"
5 -> variable == "Beast Folk"
else -> variable == "None Chosen"
}
return variable;
}
override fun info5(selects: Int) {
}
}
CodePudding user response:
Do the following:
override fun info4(type: Int):String {
variable = when (type) {
1 -> "Human"
2 -> "Orc"
3 -> "Elf"
4 -> "Demon Kin"
5 -> "Beast Folk"
else -> "None Chosen"
}
return variable;
}
This will work, but just like @Alex just added as a comment to your question the class design does not seem right. Consider rework it.