My code is all working well. I’m just trying to understand, that’s all! In this code block:
game_state = anvil.server.call("update")
if game_state is None:
return
if self.player_color == "green":
if game_state["GreenHand"] != self.hand:
self.hand = anvil.server.call("get_hand", "green")
if self.player_color == "blue":
if game_state["BlueHand"] != self.hand:
self.hand = anvil.server.call("get_hand", "blue")
if game_state["Board"] != self.model:
self.model = game_state[
"Board"
]
if game_state["IsGreenTurn"] != self.is_green_turn:
self.is_green_turn = game_state["IsGreenTurn"]
The first line retrieves a row from the database: return app_tables.board_state.get(id=1)
. Subsequent lines retrieve values for individual cells or fields from the row. Is the server called just once (first line)? Or is it called with every game_state['something']
line?? (If it’s called repeatedly, there’s really no need for the first line then, right?)
And, just out of curiosity, if this was something more than someone learning to program, would you use try...except
blocks to prevent exceptions? If so, is it enough to have one block around all the code, or do you surround every server call? (Again, everything is working fine, I’m just learning.)
Thank you for being my teachers