public string InitScript() { Script = new Script(); if (Settings.Script.Length > 0) { try { Script.GlobalsAdd("MGO", MGO); Script.GlobalsAdd("World", this); Script.GlobalsAdd("Session", session); Script.GlobalsAdd("AiEventHandler", aiEventHandler); Script.GlobalsAdd("GetFrameFactor", new GameAI.GetFrameFactorDelegate(GameAI.GetFrameFactor)); Script.Execute("lr = littleRunner(MGO, World, Session, AiEventHandler, GetFrameFactor)"); Script.GlobalsAdd("lr"); foreach (GameObject go in this.AllElements) { if (go.Name != null && go.Name != "") { Script.GlobalsAdd(go.Name, go); Script.Execute("lr.Handler." + go.Name + " = EventAttrDict()"); } } Script.Execute("handler = lr.Handler"); // very important! because Script.cs needs access to Globals["handler"]. Script.GlobalsAdd("handler"); Script.Execute(Settings.Script); Script.Init = false; } catch (NullReferenceException) { return null; // Script closed game! } catch (Exception e) { return e.GetType().FullName + ":\n" + e.Message; } } return ""; }