# HG changeset patch # User Wuzzy # Date 1535742427 -7200 # Node ID a62408ee8281e692ae29a328a90370ecbd15446f # Parent ade61b4eb63f0bb75f54a6b703d0498f652d01e7 Allow script to be missing when calling HedgewarsScriptLoad, return true/false based on success diff -r ade61b4eb63f -r a62408ee8281 ChangeLog.txt --- a/ChangeLog.txt Fri Aug 31 20:35:13 2018 +0200 +++ b/ChangeLog.txt Fri Aug 31 21:07:07 2018 +0200 @@ -107,6 +107,7 @@ + New call: GetLaserSight(): Returns true if laser sight (as utility) is currenctly active (ignoring sniper rifle) + New call: IsHogHidden(gear): Returns true if hog is hidden + Changed call: AddTeam: 2nd param. color: Accepts negative value to use a default clan color from player settings + + Changed call: HedgewarsScriptLoad: Now returns true or false based on success + Change callback: onGearResurrect: 2nd parameter for visual gear spawned at resurrect position (might be nil) + New parameter: SetAmmoTexts: 5th param. showExtra: Set to false to hide texts like “Not yet available” + New parameter: ShowMission: 6th param. forceDisplay: Set to true to prevent this particular mission panel to be hidden manually by player diff -r ade61b4eb63f -r a62408ee8281 hedgewars/uScript.pas --- a/hedgewars/uScript.pas Fri Aug 31 20:35:13 2018 +0200 +++ b/hedgewars/uScript.pas Fri Aug 31 21:07:07 2018 +0200 @@ -34,7 +34,7 @@ procedure ScriptPrintStack; procedure ScriptClearStack; -procedure ScriptLoad(name : shortstring; mustExist : boolean); +function ScriptLoad(name : shortstring; mustExist : boolean) : boolean; procedure ScriptOnPreviewInit; procedure ScriptOnGameInit; procedure ScriptOnScreenResize; @@ -3066,12 +3066,16 @@ function lc_hedgewarsscriptload(L : Plua_State) : LongInt; Cdecl; +var success : boolean; begin if CheckLuaParamCount(L, 1, 'HedgewarsScriptLoad', 'scriptPath') then - ScriptLoad(lua_tostring(L, 1), true) + begin + success:= ScriptLoad(lua_tostring(L, 1), false); + lua_pushboolean(L, success); + end else - lua_pushnil(L); - lc_hedgewarsscriptload:= 0; + lua_pushboolean(L, false); + lc_hedgewarsscriptload:= 1; end; @@ -3560,7 +3564,7 @@ end; // ⭒⭐⭒✨⭐⭒✨⭐☆✨⭐✨✧✨☆✨✧✨☆⭒✨☆⭐⭒☆✧✨⭒✨⭐✧⭒☆⭒✧☆✨✧⭐☆✨☆✧⭒✨✧⭒☆⭐☆✧ -procedure ScriptLoad(name : shortstring; mustExist : boolean); +function ScriptLoad(name : shortstring; mustExist : boolean) : boolean; var ret : LongInt; s : shortstring; f : PFSFile; @@ -3579,6 +3583,7 @@ OutError('Script not found: ' + name, true) else AddFileLog('[LUA] Script not found: ' + name); + ScriptLoad:= false; exit; end; @@ -3602,13 +3607,15 @@ begin LuaError('Failed to load ' + name + '(error ' + IntToStr(ret) + ')'); LuaError(lua_tostring(luaState, -1)); + ScriptLoad:= false; end else begin WriteLnToConsole('Lua: ' + name + ' loaded'); // call the script file lua_pcall(luaState, 0, 0, 0); - ScriptLoaded:= true + ScriptLoaded:= true; + ScriptLoad:= true; end; end;