Author Topic: Dispose all scripts  (Read 5170 times)

0 Members and 1 Guest are viewing this topic.

Offline gumby

Dispose all scripts
« 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.

Code: [Select]
/******************************************************************************
 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: [Select]
(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: [Select]
(method (startRoom roomNum)
DisposeScripts()
                DisposeScript(DISPOSESCRIPTS_SCRIPT)
         ...
« Last Edit: January 25, 2013, 11:26:13 PM by gumby »


In the Great Underground Empire (Zork port in development)
Winter Break 2012 Rope Prop Competition

Offline Doan Sephim

Re: Dispose all scripts
« Reply #1 on: June 15, 2013, 03:29:17 PM »
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.

Offline Collector

Re: Dispose all scripts
« Reply #2 on: June 15, 2013, 05:42:26 PM »
KQII Remake Pic


SMF 2.0.19 | SMF © 2021, Simple Machines
Simple Audio Video Embedder

Page created in 0.036 seconds with 21 queries.