dialogue_state = [] iterator = 1 def monitor_stanu_dialogowego(frame): global iterator # Some frames can reset the dialogue state, like saying hello. reset_state_if_needed(frame) singleState = { "iteration": iterator, "frame": frame } dialogue_state.append(singleState) iterator += 1 return dialogue_state def reset_state_if_needed(frame): global iterator if frame['act'] == "bye": dialogue_state.clear() iterator = 1