Pop.script???

Sami_Tervo In my project I've come to situation where I _m u s t_ use load.view & discard.view-commands as many times as user wants (there is not enough memory for loading every view at f5-part at the same time). Here's an example:

if(v27 == 1){
load.view(7);
// Code which will use view 7
discard.view(7);
}

As you might guess, code above will cause inevitable out of script, but I hope that pop.script-function (aka unknown172) added to following function will save my ass this time.

if(v27 == 1){
pop.script();
load.view(7);
// Code which will use view 7
discard.view(7);
}

In preliminary tests, show.mem-function shows that max.script stays stable when I use pop.script-function. But I got a bad feeling that I solved this dilemma too easily (yes, I'm a paranoiac :) ).

So, does anyone of you know if there might appear anykind of problems due to using pop.script repeatedly? Will it fail in some point and script-size starts to grow again? Or will something else bad happen?

You'll have my sincere thanks of possible answer(s) in advance.
Andrew_Baker Well, you will go blind and hair will grow all over your palms... er, oh wait, that's for something else. Go ahead and keep popping your script or whatever it is you kids are calling it these days.
Sami_Tervo Yeah right :) Well, I created a loop for testing that pop.script/load/discard-thingie about 500 times(got bored after that) and it worked fine.

Now, a bonus question: What's the difference between push.script and pop.script? Their descriptions are same.
Andrew_Baker Well, the basic theory behind a stack is that there is a sort of array of memory, a list, where the last element in is the first element to come out (often called LIFO). Anyway, you push elements onto the stack and pop them back out. You'll recognize this behavior if you are used to discarding resources in AGI. They all need to be discarded in the reverse order they were loaded, remember? So, I'm guessing that as long as your loop doesn't load any logics other than your room logic (Logic.0 doesn't count because it was loaded first), then you shouldn't have any trouble popping scripts.
sonneveld Have you tried saving and restoring your game? That's the reason why the script exists.

You need to call push.script in your if(new_room) {..} block first or else pop.script will setup the script wrongly.

and move the pop.script to the end, so the load/discard isn't in the script at all.


if (new_room)
{
load.view(blah);
....
push.script();
}

if(v27 == 1){
load.view(7);
// Code which will use view 7
discard.view(7);
pop.script();
}


btw.. push.script and pop.script are poorly named cause the interpreter doesn't use a stack. it only stores one position.. if you use pop.script twice, it overwrites the old value.

- Nick
sonneveld push.script() - save the location of the script pointer
pop.script() - restore the location of the script pointer

- Nick
sonneveld if your case.. you probably don't even need to use push pop script.. just set flag 7 which disables script writing and then reset later


if(v27 == 1){
set(7)
load.view(7);
// Code which will use view 7
discard.view(7);
reset(7)
}


But that's ONLY if the player can't save or restore between the load and discard view commands.

- Nick
sonneveld okay, I've started writing some docs on AGI's memory and script functions. let me know if it helps. It's pretty rough atm.

http://www.ids.org.au/~nsonneve/script/sc.html

Joel: if you're interested, it's got a reimplemented ego view swapping code too. using push,pop script instead of the flags.

- Nick
Joel I don't know if I'll change my code or not. In reading your docs, I noticed that the save game buffer will fill up eventually in my game. However, it seems to me that it would be caused by someone morphing and then saving a whole bunch of times in the same room without leaving it, right?

Unless a crash seems likely to happen, I don't know if it would be worth going in and changing all the code.
sonneveld well, it is up to you. I thought it might help though. :)

I tried to move most of the code into a separate logic to ease inclusion however.

- Nick
sonneveld Writing examples in tutorials really helps you understand what you're talking about. I've updated and cleaned it up. The memory section contains most of what I know on AGI's memory stuff.

- Nick
Sami_Tervo Whew, so much new information.. Luckily I've kept that part of project in ice so I can easily fix code now.

That flag 7-thingie sounds intriguing because that loading & discarding-part happens only during combat animations, e.g. player shooting or hitting enemy NPC and player can't do anything during that.

Future looks much brighter now :)
Sami_Tervo ;D Actually f7 is only option because AGI Mouse has written it's own mousefunction over push.script's original, as Nick's doc confirmes.