I'd like to suggested a change to it to account for those that don't want it touching the path fed to it. First thing that comes to mind is changing it to something like ScenEdit_RunScript(string thepath, bool resolvepath=true) such that nothing will change for any existing Lua code in the wild. But if someone were to feed it the new second parameter and set it to false such as ScenEdit_RunScript(VP_GetScenario().FileNamePath .. '\\somescript.lua',false); the false would tell it to skip the default addition and run non-gimped. Another method could be no second parameter but instead adding a check if the string submitted .contains(@":\") || .contains(@"\\"), first check covers typical cases, the second would cover cases where it's a network share path, if either true avoid the path manipulation and just proceed to the file exists check.
Now there is some path manipulation to work around this at present, but only reliably if the scene path is under <<CMOPATH>>\Scenarios. Posted here in case anyone needs work around for that common case.
Code: Select all
-- @param scriptfilename - optional string of the script file name you want added to the prepared path.
-- @returns - nil on error, string path on return, if scriptname was provided it will be added.
function buildCMOScenePathForRunScript(strfullpath,scriptfilename)
if strfullpath ~=nil then
local a,b = strfullpath:find("\\Scenarios");
if (a ~=nil) and scriptfilename == nil then
return ".." .. strfullpath:sub(a) .. "\\";
elseif a ~=nil then
return ".." .. strfullpath:sub(a) .. "\\" .. scriptfilename;
else
print("buildCMOScenePathForRunScript(): path parameter did not contain \\Scenarios" );
end
else
print("buildCMOScenePathForRunScript(): missing required scenepath parameter.");
end
return nil;
end
--usage
buildCMOScenePathForRunScript(VP_GetScenario().FileNamePath); --just get the fixed up path
buildCMOScenePathForRunScript(VP_GetScenario().FileNamePath,"Spy7Test.lua"); -- tack on filename in root of scene folder.
-- execute from a subfolder inside the source folder for the scene
local retval = pcall(ScenEdit_RunScript,buildCMOScenePathForRunScript(VP_GetScenario().FileNamePath,"scripts\\Spy7Test.lua"));