Dan_Press
(Dan Press)
1
My question is why does this work:
switch {
case cfg.PlayNew.TreeReportingOptions.Type == "very narrow":
treeMoveWidth = 1
case cfg.PlayNew.TreeReportingOptions.Type == "narrow":
treeMoveWidth = 3
case cfg.PlayNew.TreeReportingOptions.Type == "regular":
treeMoveWidth = 8
}
BUT this does not??? Note: cfg.PlayNew.TreeReportingOptions.Type is a string
switch cfg.PlayNew.TreeReportingOptions.Type {
case "very narrow":
treeMoveWidth = 1
case "narrow":
treeMoveWidth = 3
case "regular":
treeMoveWidth = 8
}
Thank you for your time!
The second example should be working fine. This:
func main() {
treeMoveWidth := 0
treeReportingOptionsType := "narrow"
switch treeReportingOptionsType {
case "very narrow":
treeMoveWidth = 1
case "narrow":
treeMoveWidth = 3
case "regular":
treeMoveWidth = 8
}
fmt.Println("treeMoveWidth =", treeMoveWidth)
}
… prints the following:
treeMoveWidth = 3
You can run it yourself on the playground.
4 Likes
Dan_Press
(Dan Press)
3
Thanks turned out there was an unprintable character in the code so that is why it would not compile.
1 Like
system
(system)
Closed
4
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.