Community
SCI Programming => SCI Community How To's & Tutorials => Topic started by: gumby on January 25, 2013, 10:27:25 PM
-
Okay, not all the scripts but as many as possible. I had to exclude a couple to keep the game running correctly.
Anyway, here's a really small script that will do the task. As far as I know, this can be called safely at any time within a room script. I use it in Zork when I've loaded up a ton of scripts and have no idea what to unload and I'm out of heap space.
It won't unload Main.sc, Controls.sc, itself, and the current room script and any script number above 988.
/******************************************************************************
DisposeScripts.sc
Unloads all scripts (with exceptions)
******************************************************************************/
(include "sci.sh")
(include "game.sh")
/******************************************************************************/
(script DISPOSESCRIPTS_SCRIPT)
(use "main")
/******************************************************************************/
(procedure public (DisposeScripts)
(var i)
(for (= i 1) (< i 989) (++i) // start at 1, excludes Main.sc
(if (<> i gRoomNumber and <> i DISPOSESCRIPTS_SCRIPT and <> i CONTROLS_SCRIPT)
DisposeScript(i)
)
)
)
/******************************************************************************/
Additionally, this code could possibly replace this section of code in Main.sc:
(method (startRoom roomNum)
DisposeLoad(
NULL
FILEIO_SCRIPT JUMP_SCRIPT EXTRA_SCRIPT WINDOW_SCRIPT
TIMER_SCRIPT FOLLOW_SCRIPT REV_SCRIPT DCICON_SCRIPT
DOOR_SCRIPT AUTODOOR_SCRIPT WANDER_SCRIPT AVOID_SCRIPT
)
DisposeScript(DISPOSELOAD_SCRIPT)
...
like this:
(method (startRoom roomNum)
DisposeScripts()
DisposeScript(DISPOSESCRIPTS_SCRIPT)
...
-
I suspect I am experiencing some heap fragmentation because sometimes rooms "works" and other times I get the out of heap message. Will implementing this script help with that?
Additionally, is there any way to offload heap space or increase it in some clever way? Because I am not the best scripter in the world and my code tends to be "less than efficient" I might say.
-
There is also this: http://sciwiki.sierrahelp.com/index.php?title=Memory_Management