public static async Task Load(Script <object>?scr) { Simulation.Pause = true; Simulation.GravityEnabled = true; Simulation.SimDuration = 0; Ui.ClearPropertyWindows(); Simulation.Clear(); Render.WorldCache = Array.Empty <BaseObject>(); Simulation.AttractorsCache = Array.Empty <PhysicalObject>(); Simulation.Player = null; My = new ExpandoObject(); Program.CurrentPalette = Palette.Default; Simulation.Add(new Box(-5000, -5100, 10000, 100, Color.Black, true, "bottom", true)); Simulation.Add(new Box(-5000, 5000, 10000, 100, Color.Black, true, "top", true)); Simulation.Add(new Box(-5100, -5000, 100, 10000, Color.Black, true, "left", true)); Simulation.Add(new Box(5000, -5000, 100, 10000, Color.Black, true, "right", true)); if (scr != null) { Console.WriteLine(L["Build start"]); Script = scr; Console.WriteLine(L["Build finished"]); Console.WriteLine(L["Script started"]); try { await Script.RunAsync().ConfigureAwait(true); //Script.CreateDelegate()(); } catch (Exception e) { var text = L["Error while loading script:"] + "\n" + e; Console.WriteLine(text); var msgbox = new MessageBox(L["Error"], text, new[] { "OK" }); Ui.Gui.Add(msgbox); msgbox.SizeLayout = new Layout2d("800", "200"); msgbox.PositionLayout = new Layout2d("&.w / 2 - w / 2", "&.h / 2 - h / 2"); msgbox.ButtonPressed += delegate { msgbox.CloseWindow(); Ui.Gui.Remove(msgbox); msgbox.Dispose(); }; } Console.WriteLine(L["Script finished"]); Simulation.Player?.Forces.Add(Program.MoveForce); } Simulation.UpdatePhysicsInternal(0); Loaded = true; Simulation.Pause = false; Simulation.TogglePause(); }