Skip to content
This repository has been archived by the owner on Jan 5, 2024. It is now read-only.

Commit

Permalink
Fixed updates not being called
Browse files Browse the repository at this point in the history
  • Loading branch information
Causeless committed Nov 5, 2023
1 parent b2f3d42 commit 3d51de1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions Activities/GAScripted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ int GAScripted::ReadProperty(const std::string_view &propName, Reader &reader) {

int GAScripted::Save(Writer &writer) const {
// Call the script OnSave() function, if it exists
g_LuaMan.GetMasterScriptState().RunScriptString("if " + m_LuaClassName + " and " + m_LuaClassName + ".OnSave then " + m_LuaClassName + ":OnSave(); end");
auto saveItr = m_ScriptFunctions.find("OnSave");
if (saveItr != m_ScriptFunctions.end()) {
g_LuaMan.GetMasterScriptState().RunScriptFunctionObject(saveItr->second.get(), "_G", m_LuaClassName, {}, {}, {});
}

GameActivity::Save(writer);

Expand Down Expand Up @@ -311,7 +314,7 @@ int GAScripted::Start() {
// Call the create function, but only after first checking if it exists
auto createItr = m_ScriptFunctions.find("StartActivity");
if (createItr != m_ScriptFunctions.end()) {
if ((error = g_LuaMan.GetMasterScriptState().RunScriptFunctionObject(createItr->second.get(), m_LuaClassName, "", {}, { initialActivityState == ActivityState::NotStarted ? "true" : "false" }, {})) < 0) {
if ((error = g_LuaMan.GetMasterScriptState().RunScriptFunctionObject(createItr->second.get(), "_G", m_LuaClassName, {}, { initialActivityState == ActivityState::NotStarted ? "true" : "false" }, {})) < 0) {
return error;
}
}
Expand Down Expand Up @@ -358,7 +361,7 @@ void GAScripted::SetPaused(bool pause) {
// Call the defined function, but only after first checking if it exists
auto pauseItr = m_ScriptFunctions.find("PauseActivity");
if (pauseItr != m_ScriptFunctions.end()) {
g_LuaMan.GetMasterScriptState().RunScriptFunctionObject(pauseItr->second.get(), m_LuaClassName, "", {}, { pause ? "true" : "false" }, {});
g_LuaMan.GetMasterScriptState().RunScriptFunctionObject(pauseItr->second.get(), "_G", m_LuaClassName, {}, { pause ? "true" : "false" }, {});
}

// Pause all global scripts
Expand All @@ -381,7 +384,7 @@ void GAScripted::End() {
// Call the defined function, but only after first checking if it exists
auto endItr = m_ScriptFunctions.find("EndActivity");
if (endItr != m_ScriptFunctions.end()) {
g_LuaMan.GetMasterScriptState().RunScriptFunctionObject(endItr->second.get(), m_LuaClassName, "", {}, {}, {});
g_LuaMan.GetMasterScriptState().RunScriptFunctionObject(endItr->second.get(), "_G", m_LuaClassName, {}, {}, {});
}

// End all global scripts
Expand Down Expand Up @@ -442,7 +445,7 @@ void GAScripted::Update() {
// Call the defined function, but only after first checking if it exists
auto updateItr = m_ScriptFunctions.find("UpdateActivity");
if (updateItr != m_ScriptFunctions.end()) {
g_LuaMan.GetMasterScriptState().RunScriptFunctionObject(updateItr->second.get(), m_LuaClassName, "", {}, {}, {});
g_LuaMan.GetMasterScriptState().RunScriptFunctionObject(updateItr->second.get(), "_G", m_LuaClassName, {}, {}, {});
}

UpdateGlobalScripts(false);
Expand Down
2 changes: 1 addition & 1 deletion Activities/GAScripted.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class GAScripted : public GameActivity {

public:

ScriptFunctionNames("StartActivity", "UpdateActivity", "PauseActivity", "EndActivity", "OnSave");
ScriptFunctionNames("StartActivity", "UpdateActivity", "PauseActivity", "EndActivity", "OnSave", "CraftEnteredOrbit");

// Concrete allocation and cloning definitions
EntityAllocation(GAScripted);
Expand Down

0 comments on commit 3d51de1

Please sign in to comment.