Don't error in update_story_chunk if chunk index doesn't exist

This commit is contained in:
Gnome Ann 2022-01-21 21:19:32 -05:00
parent 9cddaa8041
commit bf2b02d366

View File

@ -3237,6 +3237,8 @@ def update_story_chunk(idx: Union[int, str]):
else: else:
# Actions are 0 based, but in chunks 0 is the prompt. # Actions are 0 based, but in chunks 0 is the prompt.
# So the chunk index is one more than the corresponding action index. # So the chunk index is one more than the corresponding action index.
if(idx - 1 not in vars.actions):
return
text = vars.actions[idx - 1] text = vars.actions[idx - 1]
item = html.escape(text) item = html.escape(text)
@ -3365,6 +3367,8 @@ def inlineedit(chunk, data):
else: else:
if(chunk-1 in vars.actions): if(chunk-1 in vars.actions):
vars.actions[chunk-1] = data vars.actions[chunk-1] = data
else:
print(f"WARNING: Attempted to edit non-existent chunk {chunk}")
setgamesaved(False) setgamesaved(False)
update_story_chunk(chunk) update_story_chunk(chunk)
@ -3386,6 +3390,8 @@ def inlinedelete(chunk):
else: else:
if(chunk-1 in vars.actions): if(chunk-1 in vars.actions):
del vars.actions[chunk-1] del vars.actions[chunk-1]
else:
print(f"WARNING: Attempted to delete non-existent chunk {chunk}")
setgamesaved(False) setgamesaved(False)
remove_story_chunk(chunk) remove_story_chunk(chunk)
emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True) emit('from_server', {'cmd': 'editmode', 'data': 'false'}, broadcast=True)