Script Buffer Error

Randy In a room, I need the background to change depending upon a set of criteria within that room. There are 3 different backgrounds that will be cycled through and I only need them as backgrounds (all three backgrounds have a priority screen of all red) so I do not need to worry about assigning/reassigning priorities when I display those pictures.

I am using the standard code included in the template game to display a background which I think looks something like below. (I'm doing this from memory, so please bear with me):
load(14);
draw.pic(14);
show.pic();
discard(14);


In that room, when a particular criteria is met a flag is set which cues the next bit of code and then resets that flag:
load(15);
draw.pic(15);
show.pic();
discard(15);


...and again with another for another flag:
load(16);
draw.pic(16);
show.pic();
discard(16);


My problem is that when the flag is set which cues the code to display the original picture again:
load(14);
draw.pic(14);
show.pic();
discard(14);


I get the following error message "Script buffer overflow Maximum size = 50"

I was pretty sure the discard() command removed the loaded picture from memory. Does anyone know why I am getting this error and how to get around it?

Thanks for your help
sonneveld ok, I'm definately writing that memory tutorial now.

The script is actually something different from the memory heap in the interpeter but it is closely related.

The script is a list of all the resource actions in a particular room. loads, discards, add.to.pics, show.pic, things like that. The script is saved with every save game so the interpreter can load up resources in the EXACT order they were loaded.

The problem is that if you load, discard, load, discard continuously, it will fill up the script until it runs out. You can increase the script size (only once! at the start of the program! before you load anything else!) but it's only a temporary fix since you'll run out of script eventually.

There's a fix in another thread where I proposed disabling script writing, loading/discard, then enabling scripting again. but it gets fiddly because you need work arounds for savegames as well.

I'll post a link to the other memory thread here.

The best solution is to call new.room each time you swap backgrounds and add special code to make sure the ego and other objects are positioned and animated.

That's essentially what happens when you swap RGB modes when you're running in cga mode anyway. (the interpeter needs to reload all the views.. so it reloads everything to make sure it's in the same order).. but I'm digressing.

I hope that helps.

- Nick
sonneveld Link to thread on Memory Management Problem

- Nick
Randy I really would like to continue using the effect of switching background images in a specific portion of my game if at all possible. You mentioned the ability to disable script writing. Suppose I disable the script writing for just this one room. Could I also disable the Save Game ability for this particular room as well? It wouldn't hinder gameplay since this room is an arcade sequence and I think users would understand not being able to save games during this sequence.

I'm not fully aware of all the nuances of script writing and save game functions. Supposing I do this (disable script writing and save game for this room) Do you see any other potential problems that might come up?

Also, how would I go about disabling these two functions?
sonneveld It's all detailed in the linked thread.. but basically there's a flag (in the agi studio "special flags" docs) that disables script writing.

Make sure you disable saves and swapping rgb modes as well if you don't want to work around them

- Nick
Andrew_Baker Your best bet is to do something like this:

First, in defines.txt, create a variable to hold the proper background number, like bkgrnd_no

#define bkgrnd_no v100

Then, in the logic code where you are swapping backgrounds, you'll want to include some conditionals based on this variable

if (bkgrnd_no == 0) {
load.pic(0);
}
if (bkgrnd_no == 1) {
load.pic(1);
}
...

if (bkgrnd_no == n) {
load.pic(n);
}

Put this code in the INITIALIZATION block, that first conditional which says if (new_room) {...} . Make sure the old load.pic() command is deleted.

Then, whenever something happens in that room to change the background, you set the variable bkgrnd_no to the appropriate integer, and call new.room(x), where x is the same room. This will reload the whole room, but only load the picture appropriate to the circumstances. I often call new.room() in animated or shifting code because it seems to get rid of a lot of glitches and also keeps the script buffer from overloading.

As far as coding to keep the ego in the proper place, as long as you don't have any if (previous_room_no) {...} conditionals with an else{...} after it that sets a default ego location, you should be fine. The variables holding the ego's position should remain the same.

Trust Nick, new.room() is the way to go.
Joel Even if you do have those if (prev_room_no == ...) things with an unconditional else at the end, you could work around that by adding another if (prev_room_no == ...) condition but use the current room number and just leave the code block empty. For example, if logic 10 has this code:
if (new_room)
{
// ...

if (prev_room_no == 9)
{
position(ego, 100, 100);
}
else
{
if (prev_room_no == 8)
{
position(ego, 99, 99);
}
else
{
position(ego, 89, 120);
}
}
}


You could simply change the code to look like this:

if (new_room)
{
// ...

if (prev_room_no == 9)
{
position(ego, 100, 100);
}
else
{
if (prev_room_no == 8)
{
position(ego, 99, 99);
}
else
{
if (prev_room_no == 10)
{
}
else
{
position(ego, 89, 120);
}
}
}
}


Of course, you'll need one of the updated versions of AGI Studio for that to compile, because version 1.31 doesn't allow empty code blocks.
Randy Thanks for all your help. I went the easy road and disabled the script writing as well as the save game option in the initialization code for this room (I couldn't find any RGB mode controller) and it works like a champ. When the user leaves this room I enable script writing and save game right before sending them to the next room.

The room in question has so many variables & flags and so many things going on that, even though the method of resetting the room might be better, I would rather not try to deal with the complications that might arise from that solution.

Again, thanks for your help. I am looking forward to finishing this game.