Closed richardspirit closed 3 years ago
Decided to solve this with the following function which eliminates users error
func gametype() (typereturn string) { m := make(map[string]string)
// Set key/value pairs using typical `name[key] = val`
m["k1"] = fmt.Sprintf("%-30s", "Play")
m["k2"] = fmt.Sprintf("%0s", "Brawl")
m["k3"] = fmt.Sprintf("%-30s", "Standard Ranked")
m["k4"] = fmt.Sprintf("%0s", "Traditional Standard Play")
m["k5"] = fmt.Sprintf("%-30s", "Traditional Standard Ranked")
m["k6"] = fmt.Sprintf("%0s", "Traditional Historic Ranked")
m["k7"] = fmt.Sprintf("%-30s", "Historic Ranked")
m["k8"] = fmt.Sprintf("%0s", "Historic Brawl")
m["k9"] = fmt.Sprintf("%-30s", "Bot")
m["k10"] = fmt.Sprintf("%0s", "Event")
fmt.Println("1:", m["k1"], " 2:", m["k2"])
fmt.Println("3:", m["k3"], " 4:", m["k4"])
fmt.Println("5:", m["k5"], " 6:", m["k6"])
fmt.Println("7:", m["k7"], " 8:", m["k8"])
fmt.Println("9:", m["k9"], "10:", m["k10"])
in := bufio.NewScanner(os.Stdin)
in.Scan()
choice, _ := strconv.Atoi(in.Text())
switch choice {
case 1:
typereturn = "Play"
case 2:
typereturn = "Brawl"
case 3:
typereturn = "Standard Ranked"
case 4:
typereturn = "Traditional Standard Play"
case 5:
typereturn = "Traditional Standard Ranked"
case 6:
typereturn = "Traditional Historic Ranked"
case 7:
typereturn = "Historic Ranked"
case 8:
typereturn = "Historic Brawl"
case 9:
typereturn = "Bot"
case 10:
fmt.Println("Event Name:")
in.Scan()
typereturn = in.Text()
typereturn = strings.TrimSpace(typereturn)
default:
println("Invalid Entry")
gametype()
}
return typereturn
}
this does not work: