Dispose All Scripts
From SCI Wiki
Revision as of 18:44, 30 October 2013 by Andrew Branscom (talk | contribs) (Created page with "Originally posted on the SCI Programming Forum by Gumby. Disposing of as many scripts as possible can help preserve heap space. I had to e...")
Originally posted on the SCI Programming Forum by Gumby.
Disposing of as many scripts as possible can help preserve heap space. I had to exclude a couple to keep the game running correctly.
Here is 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.
Code:
/******************************************************************************
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:
Code:
(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:
Code:
(method (startRoom roomNum)
DisposeScripts()
DisposeScript(DISPOSESCRIPTS_SCRIPT)
...
See Also