Skip to content

Commit edd5f95

Browse files
committed
Engine: hotfix dialog script's return value lost in case of post-events
1 parent e1e509a commit edd5f95

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Engine/script/script.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,17 @@ RunScFuncResult RunScriptFunction(const RuntimeScript *script, const String &tsn
394394
quit_with_script_error(tsname);
395395
}
396396

397+
// FIXME: here we save the return value of the current called function,
398+
// because anything scheduled for the post-script processing will be run by the same executor,
399+
// and on the same thread, and may replace "return value" field saved in a executor.
400+
// That's ugly. Should revise and redesign this later. BTW, ScriptExecutor keeping
401+
// last return value is also a hack, used currently only by dialogs. This should be done differently.
402+
const int ret_value = scriptExecutor->GetReturnValue();
397403
if (!scriptThreadMain->IsBusy())
398404
{
399405
PostScriptProcessing(tsname);
400406
}
407+
scriptExecutor->SetReturnValue(ret_value); // restore saved ret value
401408

402409
// restore cached error state
403410
cc_error(cachedCcError);

Engine/script/scriptexecutor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class ScriptExecutor
151151
const RuntimeScriptValue *GetCurrentStack() const { return _registers[SREG_SP].RValue; }
152152
// Get latest return value
153153
int GetReturnValue() const { return _returnValue; }
154-
// TODO: this is a hack, required for dialog script; redo this later!
154+
// FIXME: this is a hack, required for dialog script; redo this later!
155155
void SetReturnValue(int val) { _returnValue = val; }
156156

157157
// Get the script's execution position and callstack as human-readable text

0 commit comments

Comments
 (0)