Skip to content

View not updating after Update runs #1343

Answered by meowgorithm
cronyakatsuki asked this question in Q&A
Discussion options

You must be logged in to vote

This looks cool!

View actually is being called after pressing space, so there's likely still be an issue in your logic. To demonstrate I added a counter that shows the current step in the game which redraws after pressing space. Also, note that you weren't returning the new model after so I fixed that as well.

Here's the diff:

diff --git a/main.go b/main.go
index 4bb3ac6..7e41b7d 100644
--- a/main.go
+++ b/main.go
@@ -18,6 +18,7 @@ const (
 type gol struct {
 	grid   [ROW][COL]int
 	buffer [ROW][COL]int
+	step   int
 }
 
 // Create array that holds field's to check for neighbours
@@ -74,6 +75,7 @@ func (g gol) Life() tea.Model {
 			}
 		}
 	}
+	g.step++
 	return g
 }
 
@@ -86,8 +88,7 @@

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@cronyakatsuki
Comment options

Answer selected by cronyakatsuki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants